我的代码:
import requests
import os
import cookielib
from bs4 import BeautifulSoup
url = 'http://www.bseindia.com/corporates/Insider_Trading.aspx'
jar = cookielib.CookieJar()
r = requests.get(url, cookies=jar)
soup = BeautifulSoup(r.content)
view_state = soup.find(id ="__VIEWSTATE")
headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Referer":"http://www.bseindia.com/corporates/Insider_Trading.aspx"}
payload = {"__EVENTTARGET": "ctl00$ContentPlaceHolder1$lnkDownload", "__EVENTARGUMENT": "","__VIEWSTATE":view_state,"__EVENTVALIDATION":"g8vXAQKJsYefCgK6rpDlDwL8np6XAwLl44LQAgK0w8TlCwKHlNXODQKW0sv1BgLei4rQAwKExL/8BQLJsJHgCQLhsb3hCQLJsLmaCAL40JWiCgK9vIn8DA==",
"myDestination1":"#","WINDOW_NAMER":"1","myDestination":"#","ctl00$ContentPlaceHolder1$fmdate":"20131003","ctl00$ContentPlaceHolder1$eddate":"20131009",
"ctl00$ContentPlaceHolder1$hdnCode":"","ctl00$ContentPlaceHolder1$txtDate":"","ctl00$ContentPlaceHolder1$txtTodate":"","ctl00$ContentPlaceHolder1$GetQuote1$hdnCode":"",
"ctl00$ContentPlaceHolder1$GetQuote1$smartSearch":"","ctl00$ContentPlaceHolder1$ddlregulation":"ALL"}
r = requests.post(url,cookies=jar,headers=headers,data=payload)
print r.content
我正在尝试做的是从上面的 url 下载一个 csv 文件,但出现问题中提到的错误。
我哪里错了?