当前位置:首页 > Python教程 > python技巧

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.html14     file_ = open(document,w)   
15    file_.write(msg)
16    file_.close()
1718     path_wk = rC:Python27wkhtmltopdfbinwkhtmltopdf.exe19     config = pdfkit.configuration(wkhtmltopdf = path_wk)
2021‘‘‘保存pdf到本地‘‘‘22     pdfkit.from_url(url, rD:are you codingpdftaobao.pdf, configuration=config)

 

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


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐