首先需要使用wkhtmltox,链接https://wkhtmltopdf.org/downloads.html,对于window可以用32位
Flavor | Downloads | Comments | |
---|---|---|---|
Windows | MSVC 2015 | win32 / win64 | Installer for Windows Vista or later |
参考链接https://blog.youkuaiyun.com/suzyu12345/article/details/50759482/
可以由https://leetcode-cn.com/problemset/all/ 得到new.txt
使用pdfkit
import re
import os
import pdfkit
bookpath=os.getcwd()
#new.txt中有链接
contentName=bookpath+'\\new.txt'
i=0
txtFileObj=open(contentName)
for j in txtFileObj:
j=str(j)
#正则表达式提取题目链接
temp=re.search('\(\/problem.*?\)',j)
if(temp):
i=i+1
temp=temp.group()
#temp得到实际链接
temp=r'https://leetcode-cn.com/'+temp[2:len(temp)-1]+r'/description/'
name=str(i)+r'.pdf'
pdfkit.from_url(temp,name)
#print(temp)
print(i)