python 保存网页为pdf到本地


 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 = r'C:\Python27\wkhtmltopdf\bin\wkhtmltopdf.exe'
19     config = pdfkit.configuration(wkhtmltopdf = path_wk)
20     
21     '''保存pdf到本地'''
22     pdfkit.from_url(url, r'D:\are you coding\pdf\taobao.pdf', configuration=config)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM