如何使用的HttpRequest和HtmlAgilityPack在一起吗? [英] How to use httpRequest and HtmlAgilityPack together?

查看:201
本文介绍了如何使用的HttpRequest和HtmlAgilityPack在一起吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图登录到一个网页,并得到一些数据出的页面,但我的问题是,在这些登录信息填写。

So I am trying to log into a page and get some data out of that page, but my problem is filling in these Login information.

什么我有试过吗?在URL发布的数据。通过简单地将postname恩的价值,像这样: http://stackoverflow.com?postLogin=myUsername&postPassword=myPassword 。我给这个网址的请求。它给了我一个错误。我检查了网址上的浏览器。看来,它并填写用户名,但不是密码文本框(我已经写了正确的postnames)。

What have I tried? Posting data in url. By simply adding the postname en the value like so: http://stackoverflow.com?postLogin=myUsername&postPassword=myPassword. I sent a request with this url. It gave me an error. I checked out the url on a browser. It seems that it does fill in the username but not the password textbox(I have written the correct postnames).

我也看到有人提建议使用HtmlAgilityPack填写数据(其中被标记为答案)。但经过搜索这似乎是不可能单独与HtmlAgilityPack做到这一点。 HtmlAgilityPack是良好的解析HTML,而不是填充它。所以我得出一个结论,我也许不得不使用的HttpRequest和HtmlAgilityPack的组合。

I also saw someone giving advice to use HtmlAgilityPack to fill in the data(which was marked as answer). But after more searching it seemed impossible to do it with HtmlAgilityPack alone. HtmlAgilityPack is good for parsing html rather than filling it. So I came to a conclusion that I perhaps have to use a combination of httpRequest and HtmlAgilityPack.

我可能是错的,所以如果你有更好的建议,这将有助于将随意点我出了正确的方向。

I might be wrong, so if you have a better suggestion that would help be free to point me out in the right direction.

但是,如果我想去做这样,我不知道如何将它们一起使用这两种。
我第一次送我的WebRequest登录页面来获得htmlpage。我从我的HttpWebRequest,但我怎么让我的网页浏览器类解析响应,事后让我的WebRequest与用户名,密码,当然,尝试后的数据发送到提交?

But if I am suppose to do it this way, I am not sure how to use both of them together. I first send my webrequest to the login page to get the htmlpage. I get the response from my httpWebRequest, but how do I let my Webbrowser class parse that response and afterwards let my webrequest send in the post data with username, password and of course try to submit it?

如果你想给在C#中的答案,我想我将能够阅读和翻译它自己。

If you want to give answer in c# i think i would be able to read it and translate it myself.

编辑:我只是用小提琴手,并获得要发送的8个员额。这是否意味着我已经发出的所有8藏汉到URL?

edit: I just used fiddler and got 8 posts that are being sent. Does this mean i have sent all 8 aswell to the url ?

推荐答案

有没有必要使用web浏览器的解析HTML。您可以查找在HTML作为一个字符串或使用库如 http://htmlagilitypack.codeplex.com/所需要的信息做解析。

There is no need to use WebBrowser for parsing HTML. You can either look for the needed information in the HTML as a string or use library like http://htmlagilitypack.codeplex.com/ to do the parsing.

此外,你会发现 http://www.fiddler2.com/ 非常有用的,以确定哪些信息的浏览器发送到Web页面,以便您可以使用HttpWebRequest的(头,GET / POST值等)重现行为。

Also you will find http://www.fiddler2.com/ very useful to determine exactly what information the browser sends to the web page so you can reproduce the behavior using HttpWebRequest (headers, GET/POST values etc.).

您也可以尝试 HTTP ://www.chadsowald.com/software/fiddler-extension-request-to-code - 扩展提琴手自动生成模仿浏览器请求的.NET代码

You could also try http://www.chadsowald.com/software/fiddler-extension-request-to-code - extension to Fiddler that automatically generates .NET code that imitates the browser request.

这篇关于如何使用的HttpRequest和HtmlAgilityPack在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆