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

时间:2022-04-27 06:43:45

Does anyone have any recommendations for performing the following in ASP.NET code:

有没有人有任何建议在ASP.NET代码中执行以下操作:

1) Login into a password protected site with a username and password (target site is not necessarily ASP.NET)

1)使用用户名和密码登录受密码保护的站点(目标站点不一定是ASP.NET)

2) Navigate to a specific page and/or perform a search

2)导航到特定页面和/或执行搜索

3) Pull specific data from the page (this is the easy part)

3)从页面中提取特定数据(这是简单的部分)

Although using an API would be nice, the source site does not provide this capability.

虽然使用API​​会很好,但源站点不提供此功能。

The login is very straightforward (Username, Password, Submit Button) -- no CAPTCHA's, etc...

登录非常简单(用户名,密码,提交按钮) - 没有CAPTCHA等...

2 个解决方案

#1


Check out my answer to this question:
surfing with the same CookieContainer

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

在.Net中内置了一个WebClient类,但它在通过身份验证方面并不是很擅长,所以我前段时间写了这篇文章以帮助完成繁琐的工作。不幸的是,您仍然需要研究响应以了解要发送的请求以及如何解析结果。并确保阅读我的免责声明:坦率地说,我的部分代码不是很好,而且它在VB.Net中(这对某些人来说是一个问题)。但主要是效果很好。

#2


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

您可以使用System.Net.WebClient类执行此操作。

#1


Check out my answer to this question:
surfing with the same CookieContainer

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

在.Net中内置了一个WebClient类,但它在通过身份验证方面并不是很擅长,所以我前段时间写了这篇文章以帮助完成繁琐的工作。不幸的是,您仍然需要研究响应以了解要发送的请求以及如何解析结果。并确保阅读我的免责声明:坦率地说,我的部分代码不是很好,而且它在VB.Net中(这对某些人来说是一个问题)。但主要是效果很好。

#2


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

您可以使用System.Net.WebClient类执行此操作。