粗糙的邮寄要求表格数据

时间:2019-03-17 12:18:30

标签: python-2.7 post scrapy

在输入CP编号为16308 https://www.icsi.in/Student/Default.aspx?TabID=100后,我想使用草木过帐的请求获得搜索结果。

这是我的拼字游戏代码:-

def parse(self, response):
    head=response.xpath('//span[@id="dnn_ctlHeader_dnnBreadcrumb_lblBreadCrumb"]/span[@class="SkinObject"]/text()').extract_first()
    view_gen = response.xpath('//input[@id="__VIEWSTATEGENERATOR"]/@value').extract_first()
    dnn= response.xpath('//input[@id="__dnnVariable"]/@value').extract_first()
    view_state = response.xpath('//input[@id="__VIEWSTATE"]/@value').extract_first()
    view_val = response.xpath('//input[@id="__EVENTVALIDATION"]/@value').extract_first()

    data={
            '__VIEWSTATEGENERATOR':view_gen,
            '__dnnVariable':dnn,
            '__VIEWSTATE':view_state,
            '__EVENTVALIDATION':view_val,
            'dnn$ctr410$MemberSearch$txtCpNumber':'16803',
            'dnn$ctr410$MemberSearch$ddlMemberType':'0'

    }
    yield scrapy.FormRequest(response.url,formdata=data,callback=self.fun)

回复  调试:已抓取(200)https://www.icsi.in/Student/Default.aspx?tabid=100&error=An%20unexpected%20error%20has%20occurred&content=0>(引荐来源:https://www.icsi.in/Student/Default.aspx?TabID=100) []

1 个答案:

答案 0 :(得分:1)

  

响应调试:已抓取(200)   https://www.icsi.in/Student/Default.aspx?tabid=100&error=An%20unexpected%20error%20has%20occurred&content=0>   (引荐来源:https://www.icsi.in/Student/Default.aspx?TabID=100)[]

您的问题是如何避免正确解决此错误?将来尝试更加具体。

当您要抓取网页时,必须在浏览器中检查所有网页,查看与请求一起发送的所有参数,并确保对蜘蛛执行相同的操作。您的代码中有很多参数,但不是全部。

请参阅下面的代码,它实际上可以解决您的问题:

yui

您缺少参数import scrapy class MySpider(scrapy.Spider): name = 'icsi' start_urls = ['https://www.icsi.in/Student/Default.aspx?TabID=100'] search_action_url = 'https://www.icsi.in/Student/Default.aspx?TabID=100' def parse(self, response): formdata = dict() for input in response.css('form#Form input'): name = input.xpath('./@name').get() value = input.xpath('./@value').get() formdata[name] = str(value) if value else '' formdata['dnn$ctr410$MemberSearch$txtCpNumber'] = '16308' formdata['__EVENTTARGET'] = 'dnn$ctr410$MemberSearch$btnSearch' return scrapy.FormRequest(self.search_action_url, formdata=formdata, callback=self.parse_search) def parse_search(self, response): scrapy.shell.inspect_response(response, self) return ,该参数会通知您单击“搜索”按钮的网站。