我正在尝试下载门户网站上的csv文件,手动操作时我们登录到网址并点击下载CSV 按钮,然后提示保存。我们正在使用python3
我试图通过python脚本执行此操作,当我们执行此脚本时,我们得到名为Download CSV
的html页面,当我们点击时,我们通过它获得了一个csv文件。
import urllib.request
import requests
session = requests.session()
playload = {'j_username':'avinash.reddy', 'j_password':'password'}
r = session.post('https://url_of_the_portal/auth/login','data=playload')
r = session.get('URL_of_the_page_where_the_csv_file_exiests')
url='https://url_of_the_portal/review/download/bm_sis'
print ('done')
urllib.request.urlretrieve (url, "Download CSV")
答案 0 :(得分:0)
我认为它应该看起来像这个+你的登录信用卡。
url = 'http://winterolympicsmedals.com/medals.csv'
r = requests.get(url)
text = r.iter_lines()
reader = csv.reader(text, delimiter=',')
ELSE ...
import requests
from contextlib import closing
import csv
url = "http://download-and-process-csv-efficiently/python.csv"
with closing(requests.get(url, stream=True)) as r:
reader = csv.reader(r.iter_lines(), delimiter=',', quotechar='"')
for row in reader:
# Handle each row here...
print row
ELSE ...
{{1}}