如何在C#中使用Html Agility Pack刮取页面? [英] How to scrape a page using Html Agility Pack in C#?
本文介绍了如何在C#中使用Html Agility Pack刮取页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在C#中使用Html Agility Pack抓取一些页面,但服务器有时会返回Service Unavailable。任何人都可以帮助了解我最好的报废方式。谢谢。
I want to scrape some pages using Html Agility Pack in C#, but server is returning Service Unavailable sometimes. Can anyone help to know me the best way for scrapping. Thanks.
推荐答案
参见这篇文章:
Html Agility Pack - 从WWW页面中提取大量信息 [ ^ ]
See this article:
Html Agility Pack - Massive information extraction from WWW pages[^]
引用:
但服务器有时返回服务不可用
but server is returning Service Unavailable sometimes
这不太可能与HtmlAgilityPack有关;可能在服务器上只有一个问题。
It's unlikely that this has something to do with HtmlAgilityPack; probably there's just a problem at the server.
我已经解决了自己,使用了一些不同的代码。
WebClient客户端=新WebClient();
字符串downloadString = client.DownloadString(http://www.example.com/default.aspx);
HtmlAgilityPack.HtmlDocument htmlPage = new HtmlAgilityPack.HtmlDocument();
htmlPage.LoadHtml(downloadString);
,它没有任何问题。
欢呼!
Hi, I have got it solved myself, used a bit different code for that.
WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.example.com/default.aspx");
HtmlAgilityPack.HtmlDocument htmlPage = new HtmlAgilityPack.HtmlDocument();
htmlPage.LoadHtml(downloadString);
and it works without any issue.
cheers!
这篇关于如何在C#中使用Html Agility Pack刮取页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文