html字段隐藏,如何刮取动态隐藏的HTML字段(UuViewState)值?

我在代码中完全实现了请求,但在FormRequest中意识到VIEWSTATE和EVENTVALIDATION是动态的,它们随每个请求而变化。我想做的是刮去它们以便在下一个请求中提供它们。在

这两个字段都在HTML代码中提供,但隐藏了<the __VIEWSTATE>。我试着使用硒,但没有任何有用的结果。在start_urls = [

'http://www.gasunietransportservices.nl/en/dataport-pages/lng-terminals/nominations',

'http://dataport.gastransportservices.nl/default.aspx?ReportPath=%2fTransparency%2fNominationsPerNetworkpoint&ReportTitle=NominationsPerNetworkpoint&TransparencySegment=06',

]

def start_requests(self):

yield Request(

url=self.start_urls[0],

callback=self.parse

)

def parse(self, response):

sel = Selector(response)

#import ipdb; ipdb.set_trace()

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

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

formdata = {

'scriptManager': 'scriptManager|ReportViewerControl$ctl09$Reserved_AsyncLoadTarget',

'__EVENTTARGET': 'ReportViewerControl$ctl09$Reserved_AsyncLoadTarget',

'__EVENTARGUMENT': '',

'__VIEWSTATE': '{}'.format(view_state[0]),

'__VIEWSTATEGENERATOR': 'CA0B0334',

'__EVENTVALIDATION': '{}'.format(event_validation[0]),

'ReportViewerControl$ctl03$ctl00': '',

'ReportViewerControl$ctl03$ctl01': '',

'ReportViewerControl$ctl10': 'ltr',

'ReportViewerControl$ctl11': 'standards',

'ReportViewerControl$AsyncWait$HiddenCancelField': 'False',

'ReportViewerControl$ctl04$ctl03$txtValue': 'LNG Terminals',

'ReportViewerControl$ctl04$ctl05$txtValue': 'ROTTERDAM (GATE) - 301345',

'ReportViewerControl$ctl04$ctl07$txtValue': '5-10-2015 0:00:00',

'ReportViewerControl$ctl04$ctl09$ddValue': '1',

'ReportViewerControl$ctl04$ctl11$txtValue': '6-10-2015 0:00:00',

'ReportViewerControl$ctl04$ctl13$ddValue': '1',

'ReportViewerControl$ctl04$ctl15$ddValue': '1',

'ReportViewerControl$ctl04$ctl17$ddValue': '1',

'ReportViewerControl$ctl04$ctl05$divDropDown$ctl01': 'on',

'ReportViewerControl$ToggleParam$store': '',

'ReportViewerControl$ToggleParam$collapse': 'false',

'ReportViewerControl$ctl05$ctl00$CurrentPage': '',

'ReportViewerControl$ctl08$ClientClickedId': '',

'ReportViewerControl$ctl07$store': '',

'ReportViewerControl$ctl07$collapse': 'false',

'ReportViewerControl$ctl09$VisibilityState$ctl00': 'None',

'ReportViewerControl$ctl09$ScrollPosition': '',

'ReportViewerControl$ctl09$ReportControl$ctl02': '',

'ReportViewerControl$ctl09$ReportControl$ctl03': '',

'ReportViewerControl$ctl09$ReportControl$ctl04': '100',

'__ASYNCPOST': 'true',

}

yield FormRequest(

url=self.start_urls[1],

formdata=formdata,

callback=self.parse_filter,

)

def parse_filter(self, response):

import ipdb; ipdb.set_trace()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值