我登录到一个页面,我使用书签下载一个CSV文件。我只需点击链接,几秒钟后,文件就被下载到我的电脑里了。我现在正尝试着从Python中的URL自动执行“下载文件”的过程。
触发文件下载的URL如下:
app.example.com/export/org.jsp?media=yes&csv=yes
##First way
import requests
payload = {'inUserName': 'test.test@test.com','inUserPass': 'test'}
with requests.Session() as s:
p = s.post('https://app.example.com/', data=payload)
#print(p.text)
r = s.get('https://app.example.com/export/org.jsp?media=yes&csv=yes')
###Second way
import urllib
import requests
payload = {'inUserName': 'test.test@test.com', 'inUserPass': 'test'}
url = 'https://app.example.com/'
requests.post(url, data=payload)
###Third way
import urllib.request
with urllib.request.urlopen("http://app.example.com/export/org.jsp?media=yes&csv=yes") as url:
s = url.read()
#print(s)
我想避免页面抓取技术,我将登录页面,然后访问url。使用的平台没有API,我可以用不同的方式请求文件。