我正在尝试写一些代码来抓取网页。我使用spynner获取html代码并将其传递给pisa
我在运行python代码时没有看到任何错误,但是pdf生成是完全错误的。在
这是我使用的代码-
import os
import sys
import ho.pisa as pisa
import spynner
import logging
class PisaNullHandler(logging.Handler):
def emit(self, record):
pass
url = 'http://www.google.com'
br = spynner.Browser()
br.load(url)
pathToWrite = './google.html.pdf'
htmlCode = br.html
pdfFile = file(pathToWrite, "wb+")
try:
logging.getLogger("ho.pisa").addHandler(PisaNullHandler())
pdfStatus = pisa.CreatePDF(htmlCode.encode("utf-8"), pdfFile, encoding="utf8" )
if not pdfStatus.err:
pdfFile.flush()
else:
print 'Failed with error ' + pdfStatus.error
except Exception as e:
print 'pdf creation failed with error ' + str(e)
我试图从spynner保存html并通过xhtml2pdf运行它。我得到以下错误-
^{pr2}$
目前没有回答
相关问题 更多 >
编程相关推荐