将内存 html 文件传递给 pdfkit
Passing in memory html file to pdfkit
我刚刚用 python
下载了一个网站
p =urllib2.build_opener(urllib2.HTTPCookieProcessor).open('http://www.google.com')
html_content = p.read()
现在我想将其写入 pdf 文件:
pdfkit.from_file(??????,'test.pdf')
但是如何在函数中传递 html_content 呢?
它需要一个文件,但我不想先将文件保存为 html。有没有办法在 pdfkit.from_file 函数中传递获取的 html_content?
注意:我不想使用.from_url,我想先使用urllib2 来获取页面。
有pdfkit.from_string
:
....
html_content = p.read()
pdfkit.from_string(html_content,'test.pdf')
和pdfkit.from_url
:
pdfkit.from_url('http://www.google.com')
并且,pdfkit.from_file
读取文件名作为第一个参数,它也接受类似文件的对象;您可以传递 urllib....open
的 return 值,因为它是一个类似文件的对象。
我刚刚用 python
下载了一个网站p =urllib2.build_opener(urllib2.HTTPCookieProcessor).open('http://www.google.com')
html_content = p.read()
现在我想将其写入 pdf 文件:
pdfkit.from_file(??????,'test.pdf')
但是如何在函数中传递 html_content 呢? 它需要一个文件,但我不想先将文件保存为 html。有没有办法在 pdfkit.from_file 函数中传递获取的 html_content?
注意:我不想使用.from_url,我想先使用urllib2 来获取页面。
有pdfkit.from_string
:
....
html_content = p.read()
pdfkit.from_string(html_content,'test.pdf')
和pdfkit.from_url
:
pdfkit.from_url('http://www.google.com')
并且,pdfkit.from_file
读取文件名作为第一个参数,它也接受类似文件的对象;您可以传递 urllib....open
的 return 值,因为它是一个类似文件的对象。