how to scrape a page request using Viewstate parameter?

送分小仙女□ 提交于 2019-12-12 16:18:29

问题


I've been trying to scrape this website : http://www.e3050.com/Cases-Fans-PDU/C

I can scrape anything normally but moving to the next page, after debugging I found that they send the __Viewstate parameter for each page request. The viewstate parameter is stored in each page response, so I figured out that I need to get it per page and send it to the following page. I get the __viewstate using this xpath :

sel.xpath('//input[@id="__VIEWSTATE"]/@value').extract()

I also got an error, because the viewstate they send is different than the one enlisted in their page response, both parameters are 64 base encoded but the one they send per request has more data than the one I get from the page response.

how can I deal with this ? and how does they get the viewstate parameter ?

Edit: The same issue for __EVENTVALIDATION parameter.


回答1:


__VIEWSTATE is a parameter used in .net for a security reason. it's basically a hash of the referral page to the page you're requesting. it's usually embedded in an tag, you just need to extract it before each request and add it to your next request.



来源:https://stackoverflow.com/questions/26034607/how-to-scrape-a-page-request-using-viewstate-parameter

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