0

我的代码:

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 文件,但出现问题中提到的错误。

我哪里错了?

4

1 回答 1

-1

我相信你的要求没有问题。我尝试了你的代码并得到了同样的错误。

您看到的错误是用 ASP 编写的服务的常见错误。这几乎总是意味着服务器端存在配置问题。谷歌这个错误,你会看到一些可能的解决方案,因为你不拥有该服务,所以没有一个对你有用。

你确定你有正确的基本网址吗?是否有 BSE India 上的服务使用示例?

于 2013-10-09T07:58:03.340 回答