1
我试图在下面的Python链接中下载PDF文件。如何在Python中的网页上下载PDF文件
我试图下载它,但无法打开保存的文件。
我的PDF阅读器给出了“源格式不是PDF”。
有人能告诉我什么是错的?
import urllib2
def main():
url = "https://www.osapublishing.org/view_article.cfm?gotourl=https%3A%2F%2Fwww%2Eosapublishing%2Eorg%2FDirectPDFAccess%2F42C574A0-ABB6-FD11-777A24C1C4C5ADEF_274099%2Foe-21-22-27371%2Epdf%3Fda%3D1%26id%3D274099%26seq%3D0%26mobile%3Dno&org="
download_file("example", url)
def download_file(file_name, download_url):
response = urllib2.urlopen(download_url)
file = open(file_name + ".pdf", 'wb')
file.write(response.read())
file.close()
print("Completed")
if __name__ == "__main__":
main()
谢谢你的回答! –