1

我需要编写一个 C# 代码来获取网页的内容。步骤如下

  1. 浏览登录页面
  2. 我有用户名和密码,以编程方式提供并登录
  3. 然后你在详细页面
  4. 您必须在那里获取一些信息,例如(产品 ID、Des 等)
  5. 然后需要在详细视图上单击(按代码)
  6. 然后您可以从那里获得该产品的价格
  7. 现在已经完成了,所以我们可以像这样将详细信息行写入文本文件... ABC Printer::225519::285.00

请帮助我,(即使是 VB.Net 代码也可以,我可以将其转换为 C#)

4

4 回答 4

1

The WatiN library is probably what you want, then. Basically, it controls a web browser (native support for IE and Firefox, I believe, though they may have added more since I last used it) and provides an easy syntax for programmatically interacting with page elements within that browser. All you'll need are the names and/or IDs of those elements, or some unique way to identify them on the page.

于 2010-12-10T11:19:16.240 回答
1

You should be able to achieve this using the WebRequest class to retrieve pages, and the HTML Agility Pack to extract elements from HTML source.

于 2010-12-10T11:21:57.593 回答
1

是的,我下载了那个库。好东西。

谢谢你和我分享。但我对那个图书馆有疑问。我想获取数据的网站在登录页面上有一个“验证码”。

如果这可以显示图像并等待我的输入,我可以输入该值。

如果您想要一个样本,我们可以从这个库中实现它吗?

于 2010-12-13T09:24:23.223 回答
0

You should be able to achieve this by using two classes in C#, HttpWebRequest (to request the web pages) and perhaps XmlTextReader (to parse the HTML/XML response).

If you do not wish to use XmlTextReader, then I'd advise looking into Regular Expressions, as they are fantastically useful for extracting information from large bodies of text where-in patterns exist.

How to: Send Data Using the WebRequest Class

于 2010-12-10T11:19:31.963 回答