我正在尝试抓取用asp.net编写的Web应用程序。
我正在尝试执行搜索并抓取搜索结果页面。让我们说搜索页面是http://search.site.com/search/search.aspx
现在我的爬虫非常直接
class SitesearchSpider(Spider):
name = 'sitecrawl'
allowed_domains = ['search.site.org']
start_urls = [
"http://search.site.org/Search/Search.aspx"
]
def parse(self, response):
self.log("Calling Parse Method", level=log.INFO)
response = response.replace(body=response.body.replace("disabled",""))
return [FormRequest(
url="http://search.site.org/Search/Search.aspx",
formdata={'ctl00$phContent$ucUnifiedSearch$txtIndvl': '2441386'},
callback=self.after_search)]
def after_search(self, response):
self.log("In after search", level=log.INFO)
if "To begin your search" in response.body:
self.log("unable to get result")
else:
self.log(response.body)
但无论同一页面(search.aspx)仅返回到after_search回调而不是预期的searchresults.aspx与结果
这似乎是在浏览器中发生的事情
现在我浏览了文档,我不确定是否必须处理302或aspnet会话cookie。任何帮助,将不胜感激。
我建议你使用fron _response,比如:
return [FormRequest.from_response(
response,
formdata={'ctl00$phContent$ucUnifiedSearch$txtIndvl': '2441386'},