如何在 ASP.NET 中模拟网站登录,然后从页面中抓取一些数据
是否有人对在 ASP.NET 代码中执行以下操作有任何建议:
1) 使用用户名和密码登录受密码保护的站点(目标站点不一定是 ASP.NET)
2) 导航到特定页面和/或执行搜索
3) 从页面中提取特定数据(这是最简单的部分)
虽然使用 API 会很好,但源站点不提供此功能。
登录非常简单(用户名、密码、提交按钮)——没有验证码等......
Does anyone have any recommendations for performing the following in ASP.NET code:
1) Login into a password protected site with a username and password (target site is not necessarily ASP.NET)
2) Navigate to a specific page and/or perform a search
3) Pull specific data from the page (this is the easy part)
Although using an API would be nice, the source site does not provide this capability.
The login is very straightforward (Username, Password, Submit Button) -- no CAPTCHA's, etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看我对这个问题的回答:
使用相同的 CookieContainer 冲浪
.Net 中内置了一个 WebClient 类,但事实并非如此擅长通过身份验证障碍,所以我前段时间写了这篇文章来帮助完成繁重的工作。 不幸的是,您仍然需要研究响应以了解发送哪些请求以及如何解析结果。 请务必阅读我的免责声明:坦率地说,我的代码的部分不是很好,而且它是在 VB.Net 中实现的(这对某些人来说是一个问题)。 但主要是它工作得很好。
Check out my answer to this question:
surfing with the same CookieContainer
There's a WebClient class built into .Net, but it's not so good at getting through authentication barriers, so I wrote that some time ago to help with the grunt work. Unfortunately, you still need to study responses to know what requests to send and how to parse the results. And make sure to read my disclaimers: parts of my code frankly aren't very good and it's in VB.Net (which is a problem for some people). But mainly it works pretty well.
您可以使用 System.Net 来执行此操作.WebClient 类。
You can do this using the System.Net.WebClient class.