import pdfkit
user_agent = {'User-Agent':'my custom user agent'}
options = {
'custom-header': user_agent,
'custom-header-propagation':''
}
pdfkit.from_url('https://www.whatismybrowser.com/detect/what-is-my-user-agent','test.pdf', options=options)我正在使用pdfkit从一个url中制作pdf。我想设置一个自定义的用户代理字符串,但它不起作用。
我仍然在使用wkhtmltopdf用户代理。我做错了什么?
发布于 2020-07-02 21:27:20
根据GitHub上的this issue,您需要像这样传递您的自定义标头:
import pdfkit
options = {
'custom-header': [('User-Agent', 'my custom user agent')],
}
pdfkit.from_url('https://www.whatismybrowser.com/detect/what-is-my-user-agent','test.pdf', options=options)注意元组,而不是代码示例中使用的dict。
https://stackoverflow.com/questions/62697342
复制相似问题