码迷,mamicode.com
首页 > 编程语言 > 详细

python 保存网页为pdf到本地

时间:2016-09-14 12:39:21      阅读:256      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!