Problem with __VIEWSTATE, __EVENTVALIDATION, __EVENTTARGET and scrapy & splash

别说谁变了你拦得住时间么 提交于 2021-01-28 06:04:35

问题


How do i handle __VIEWSTATE, __EVENTVALIDATION, __EVENTTARGET with scrapy/splash?

I tried with

return FormRequest.from_response(response,
    [...]
    '__VIEWSTATE': response.css(
    'input#__VIEWSTATE::attr(value)').extract_first(),

But this does not work.


回答1:


You'll need to use a dict as the formdata keyword arg.

(I'd also recommend extracting into variables first for readability)

def parse(self, response):
    vs = response.css('input#__VIEWSTATE::attr(value)').extract_first()
    ev = # another extraction
    et = # a third extraction
    return scrapy.FormRequest.from_response(
        response,
        formdata={'__VIEWSTATE': vs,
            '__EVENTVALIDATION': ev,
            '__EVENTTARGET': et },
        callback=self.your_callback
    )

See this doc for more information.



来源:https://stackoverflow.com/questions/52961186/problem-with-viewstate-eventvalidation-eventtarget-and-scrapy-splash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!