【发布时间】:2018-05-18 11:05:56
【问题描述】:
就目前而言,我能够获取 PDF 链接 EXAMPLE OF THE LINK HERE 的网页内容,但我不想要网页的内容,我想要 PDF 的内容,所以我可以将内容放入我电脑上文件夹中的 PDF。
我已经成功地在不需要登录且没有代理服务器的网站上执行此操作。
相关代码:
import os
import urllib2
import time
import requests
import urllib3
from random import *
s = requests.Session()
data = {"Username":"username", "Password":"password"}
url = "https://login.url.com"
print "doing things"
r2 = s.post(url, data=data, proxies = {'https' : 'https://PROXYip:PORT'}, verify=False)
#I get a response 200 from printing r2
print r2
downlaod_url = "http://msds.walmartstores.com/client/document?productid=1000527&productguid=54e8aa24-0db4-4973-a81f-87368312069a&DocumentKey=undefined&HazdocumentKey=undefined&MSDS=0&subformat=NAM"
file = open("F:\my_filepath\document" + str(maxCounter) + ".pdf", 'wb')
temp = s.get(download_url, proxies = {'https' : 'https://PROXYip:PORT'}, verify=False)
#This prints out the response from the proxy server (i.e. 200)
print temp
something = uniform(5,6)
print something
time.sleep(something)
#This gets me the content of the web page, not the content of the PDF
print temp.content
file.write(temp.content)
file.close()
我需要帮助了解如何“下载”PDF 的内容
【问题讨论】:
-
您试图在您提供的 URL 中下载 PDF 还是我误解了您?因为我这样做没有问题
-
@EvyatarMeged 是的,这就是我想做的,我想下载 PDF。哦,糟糕,我忘了包含 download_url 声明
标签: python python-2.7 proxy python-requests