2

我不确定这是否真的被称为网络爬虫,但这就是我想要做的。

我正在使用 C# .Net 在 Visual Studio 2010 中构建一个程序。

我想找到所有具有相同第一部分的网址。

假设我有一个主页:www.mywebsite.com,并且有几个子页面:/tab1,,,/tab2/tab3

有没有办法获取所有以 url 开头的列表www.mywebsite.com

因此,通过提供www.mywebsite.com,程序返回www.mywebsite.com/tab1, www.mywebsite.com/tab2,www.mywebsite.com/tab3等。

附言。我不知道总共有多少子页面。

——下午 12:04 编辑——

抱歉没有解释。

我想知道如何在 C# 中编写一个执行上述任务的爬虫。

我只知道主 url www.mywebsite.com,目标是找到它的所有子页面。

-- 下午 12:16 编辑--

此外,主页上没有链接,html 基本上是空白的。

我只知道子页面存在,但除了提供确切的网址外,无法链接到它。

4

2 回答 2

4

Hi you may consider to parse the html content in that page it doesn't really matter how is the structure of it you just need to think to grab the links tags so the first you need do is

1- use an html parser I recommend Html Agility Pack is a very mature html parser and it got a lot of features like linq to xml among others.

2- Parse the text using regular expressions in that way you'll be able to parse whatever html tag you want without involve too much code for it

3- you need to think the depth of your links you want to crawl imagine the following scenario:

www.mywebsite.com/tab3 could contain www.mywebsite.com/tab3/link2 and www.mywebsite.com/tab3/link3 and so on so putting a limit is very important

4- you can create your own windows service and use web request to do the crawling or try to use a crawler from a third party, that depends on the purpose of what you wat to do I haven't use this but it seems ok to me, maybe it worth to take a look.

Abot C# Web Crawler

Edit:

if the page is in blank you can crawl google with site:your domain.com as your primary pag and then extract the links from the actual domain instead of google or try to crawl the robots.txt from the site.

于 2013-06-27T16:15:16.463 回答
1

如果你抓取的只是内部链接,那么你只会找到网站自己链接的子页面。如果有任何特定链接以某种方式暴露给其他网站并且它们没有在内部链接,那么如果您只是抓取相关网站,您可能会错过它们。

有几种策略:

  • 作弊:如果您正在寻找 的所有子页面turtlerescueleague.com,那么只需谷歌site:turtlerescueleague.com并抓取谷歌结果。这通常会解决网站可能具有不链接到自身但其他一些网站链接到它们的页面的问题。
  • 构建爬虫:您需要从每个 HTML 页面中提取链接,丢弃任何外部链接,检查您是否已经访问过某个链接,将新链接排入您的页面队列以访问并访问该页面!不要忘记礼貌地做这一切,即遵守 robots.txt :)。
于 2013-06-27T16:18:21.157 回答