无法抓取ASP .NET网页

时间:2010-03-24 11:42:47

标签: asp.net python

我正在尝试抓取一个ASP.NET网站但是无法从帖子中获取结果。我有以下python代码,并使用httplib2和BeautifulSoup:

conn = Http()
# do a get first to retrieve important values
page = conn.request(u"http://somepage.com/Search.aspx", "GET")

#event_validation and viewstate variables retrieved from GET here...

body = {"__EVENTARGUMENT" : "",
        "__EVENTTARGET" : "" ,
        "__EVENTVALIDATION": event_validation,
        "__VIEWSTATE" : viewstate,
        "ctl00_ContentPlaceHolder1_GovernmentCheckBox" : "On",
        "ctl00_ContentPlaceHolder1_NonGovernmentCheckBox" : "On",
        "ctl00_ContentPlaceHolder1_SchoolKeyValue" : "",
        "ctl00_ContentPlaceHolder1_SchoolNameTextBox" : "",
        "ctl00_ContentPlaceHolder1_ScriptManager1" : "ctl00_ContentPlaceHolder1_UpdatePanel1|cct100_ContentPlaceHolder1_SearchImageButton",
        "ct100_ContentPlaceHolder1_SearchImageButton.x" : "375",
        "ct100_ContentPlaceHolder1_SearchImageButton.y" : "11",
        "ctl00_ContentPlaceHolder1_SuburbTownTextBox" : "Adelaide,SA,5000",
        "hiddenInputToUpdateATBuffer_CommonToolkitScripts" : 1}

headers = {"Content-type": "application/x-www-form-urlencoded"}
resp, content = conn.request(url,"POST", headers=headers, body=urlencode(body))

当我打印content时,我似乎仍然得到与“GET”相同的结果,或者是否有一个基本概念我缺少检索ASP .NET帖子的结果值?

2 个答案:

答案 0 :(得分:2)

这在技术上不是一个答案,但您可以使用Fiddler来检查您使用python代码发送的内容与使用Web浏览器发布内容时发送的内容之间的区别。

我发现这通常有助于这些类型的情况。

答案 1 :(得分:0)

嗯,你需要首先看一下你在页面上写的内容以获取和发布,但我希望你确保这两个请求都发送不同的内容。

这是你如何做到的


if(!IsPostBack)
{
Response.Write("<h1>Get Request</h1>");
}
else
{
Response.Write("<h1>POST Request</h1>");
}

我希望您使用C#作为代码