python 如何执行浏览器打印操作

qq_33529904 2017-12-13 04:26:07
我已经用python爬虫爬取到了我所需要的网址,遍历我所需要的网址,并执行打印操作打印这些网址,保存为PDF文件,请问改使用哪个库可行
...全文
756 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2017-12-14
  • 打赏
  • 举报
回复
利用在线API

# This code converts an url to pdf in Python using SelectPdf REST API through a POST request. 
# The parameters are JSON encoded.
# The content is saved into a file on the disk.

import json
import urllib2

api_endpoint = 'http://selectpdf.com/api2/convert/'
key = 'your license key here'
test_url = 'http://selectpdf.com'
local_file = 'test.pdf'

# parameters - add here any needed API parameter 
parameters = {
	'key': key,
	'url': test_url
}

requesturl = api_endpoint
print "Calling {0}\n".format(requesturl)

try:
	request = urllib2.Request(requesturl)
	request.add_header('Content-Type', 'application/json')
	result = urllib2.urlopen(request, json.dumps(parameters))
	localFile = open(local_file, 'wb')
	localFile.write(result.read())
	localFile.close()
	print "Test pdf document generated successfully!"
except urllib2.HTTPError as e:
	print "HTTP Response Code: {0}\nHTTP Response Message: {1}".format(e.code, e.reason)
except:
	print "An error occurred!"

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧