社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
options = {
'page-size': 'Letter',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header': [
('Accept-Encoding', 'gzip')
],
'cookie': [
('cookie-name1', 'cookie-value1'),
('cookie-name2', 'cookie-value2'),
],
'outline-depth': 10,
}
options = {
'page-size': 'Letter',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header': [
('Accept-Encoding', 'gzip')
],
'cookie': [
('cookie-name1', 'cookie-value1'),
('cookie-name2', 'cookie-value2'),
],
'outline-depth': 10,
}
cover='demo.html'
pdfkit.from_file('demo.html','demo.pdf',cover=cover,options=options)
css='demo.css'
pdfkit.from_file('demo.html','demo.pdf',options=options,cover=cover,css=css)
import sys
import threading
reload(sys)
sys.setdefaultencoding('utf8')
本人爬了廖雪峰老师的`python2.7`的教程,并且做成了电子书,截图如下
这里并没有使用框架,如果有兴趣的朋友可以用框架写一个爬取全站的,这里的主要用到的是BeautifulSoup和requests,详情可以看我的博客中的python爬虫之BeautifulSoup。源代码请见pdfkit制作pdf电子书
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!