Parse a .Net Page with Postbacks

和自甴很熟 提交于 2019-12-18 07:26:07

问题


I need to read data from an online database that's displayed using an aspx page from the UN. I've done HTML parsing before, but it was always by manipulating query-string values. In this case, the site uses asp.net postbacks. So, you click on a value in box one, then box two shows, click on a value in box 2 and click a button to get your results.

Does anybody know how I could automate that process?

Thanks,

Mike


回答1:


You may still only need to send one request, but that one request can be rather complicated. ASP.Net is notoriously difficult (though not impossible) to screen scrape. Between event validation and the ViewState, it's tricky to get your requests just right. The simplest way to do it is often to use a sniffer tool like fiddler to see exactly what the http request looks like, and then just mimic that request.

If you do still need to send two requests, it's because the first request also places some state in a session somewhere, and that means whatever you use to send those requests needs to be able to send them with the same session. This often means supporting cookies.




回答2:


Watin would be my first choice. You would code the selecting and clicking, then parse the HTML after.




回答3:


I'd look at HtmlAgilityPack with the FormProcessor addon.



来源:https://stackoverflow.com/questions/1245782/parse-a-net-page-with-postbacks

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