如何在 ASP.NET 中模拟网站登录,然后从页面中抓取一些数据

发布于 2024-07-16 05:43:48 字数 222 浏览 3 评论 0原文

是否有人对在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两仪 2024-07-23 05:43:48

看看我对这个问题的回答:
使用相同的 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.

草莓味的萝莉 2024-07-23 05:43:48

You can do this using the System.Net.WebClient class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文