从网页获取html结果

时间:2013-02-09 03:35:05

标签: c# .net

我正在计划创建一个应该使用此网页(http://consultawebvehiculos.carabineros.cl/index.php)结果的movil应用程序(为了好玩)。有没有办法在我的网络代码中创建一个浏览器实例,并阅读此结果并使用Web服务发布它。 类似的东西:

var IE= new broswer("http://consultawebvehiculos.carabineros.cl/index.php");
var result=IE.FindElementByID("txtIdentityCar").WriteText(YourIdentityCar);
publicToWebSerivce(result);

更新: 使用Fiddler我可以看到http帖子是这样的:

POST http://consultawebvehiculos.carabineros.cl/index.php HTTP/1.1
Host: consultawebvehiculos.carabineros.cl
Connection: keep-alive
Content-Length: 61
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://consultawebvehiculos.carabineros.cl
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko)      Chrome/24.0.1312.57 Safari/537.17
Content-Type: application/x-www-form-urlencoded
Referer: http://consultawebvehiculos.carabineros.cl/index.php
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-ES,es;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

accion=buscar&txtLetras=CL&txtNumeros1=sk&txtNumeros2=12&vin=

可能我需要一些像webclient这样的.Net类来连接php页面......不确定。

更新:我终于找到了使用Fiddler知道总参数的解决方案,我使用了http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx中的代码

2 个答案:

答案 0 :(得分:1)

如果您只想抓取页面,我建议您使用Html Agility Pack

如果您还想显示该页面,则可以使用WebBrowser控件。

答案 1 :(得分:0)

我们一直在使用http://htmlunit.sourceforge.net/进行类似的任务。它允许您发送请求,接收响应/状态代码/等。

(它是一个Java库,因此您可以谷歌用于.Net端口或使用转换器将Java程序集转换为.Net程序集 - 请参阅http://blog.stevensanderson.com/2010/03/30/using-htmlunit-on-net-for-headless-browser-automation/获取指导。我们使用了转换方法)。