首页 > 编程语言 > 详细

python 保存网页为pdf到本地

时间:2016-09-14 12:37:04      阅读:488      评论:0      收藏:0      [点我收藏+]
 1 import urllib2
 2     import cookielib
 3     import pdfkit
 4     
 5     cj = cookielib.LWPCookieJar()
 6     opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
 7     urllib2.install_opener(opener)
 8     url = "https://www.taobao.com/"
 9     req = urllib2.Request(url)
10     ‘‘‘ 保存html到本地‘‘‘
11     operate = opener.open(req)
12     msg = operate.read()
13     document = D://1.html  
14     file_ = open(document,w)   
15     file_.write(msg)
16     file_.close()
17     
18     path_wk = rC:\Python27\wkhtmltopdf\bin\wkhtmltopdf.exe
19     config = pdfkit.configuration(wkhtmltopdf = path_wk)
20     
21     ‘‘‘保存pdf到本地‘‘‘
22     pdfkit.from_url(url, rD:\are you coding\pdf\taobao.pdf, configuration=config)

 

python 保存网页为pdf到本地

原文:http://www.cnblogs.com/jingyihiter/p/5871191.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!