如何解析c#中的网页 [英] How to parse web page in c#

查看:110
本文介绍了如何解析c#中的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。

我正在学习c#和asp.net,我需要从网页上获取信息(商品名称和价格)。我希望自己制作,而不是使用 htmlagilitypack

您可以使用哪些书籍,链接或来源建议我学习这个?

解决方案

你可以使用WebClient从页面下载html



通过网络客户端获取HTML的示例代码 [< a href =https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]



一旦掌握了资源,就由您决定。您可以使用正则表达式来标识包含价格的div等,或者您可以使用IndexOf等基本技术来搜索相关元素,然后使用Substring来提取您感兴趣的文本。


以下是一些文章 -

使用ASP.NET中的HtmlAgilityPack(HAP)刮取HTML DOM元素 [ ^ ]

Html Agility Pack - 从WWW页面中提取大量信息 [ ^ ]



HTML Agility pack有一节介绍讨论 - http://htmlagilitypack.codeplex.com/discussions [ ^ ]。


Hi there.
I am learning c# and asp.net and i need to take information from the webpage (name and price of goods) . I want to make it by myself , NOT WITH USE htmlagilitypack
What books, links, or source you can suggest me to learn this ?

解决方案

You can download the html from a page using the WebClient

Sample code for getting HTML via webclient[^]

Once you have the source it's up to you. You can use regular expressions to identify the divs etc that contain the prices, or you can use basic techniques like IndexOf to search for the relevant elements then use Substring to extract the text you're interested in.


Here are some articles -
Scraping HTML DOM elements using HtmlAgilityPack (HAP) in ASP.NET[^]
Html Agility Pack - Massive information extraction from WWW pages[^]

HTML Agility pack has a section on discussions - http://htmlagilitypack.codeplex.com/discussions[^].


这篇关于如何解析c#中的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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