如何从网址获取所有内容 [英] how to fetch all the contents from web url

查看:75
本文介绍了如何从网址获取所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网站(任何网站)获取所有内容。我有以下代码,但它不是100%正确。



I want to fetch all the content from website(any website). I have the following code but it is not 100% correct.

using (var client = new System.Net.WebClient())
    {
        var filename = System.IO.Path.GetTempFileName();
        client.DownloadFile("http://www.cnn.com", filename);
        var doc = new HAP.HtmlDocument();
        doc.OptionDefaultStreamEncoding = Encoding.UTF8;
        doc.Load(filename);

        var root = doc.DocumentNode;
        var a_nodes = root.Descendants("a").ToList();


        foreach (var a_node in a_nodes)
        {
            Console.WriteLine();
            Console.WriteLine(a_node.InnerText.Trim());
        }
    }

    Console.ReadKey();





现在我有仅使用



Now I have used just

<a>

标签在这里,但我不知道如何从其他标签一起获取数据。



任何建议!!

tag here but I am not sure how to get data from other tags all together.

Any suggestons!!

推荐答案

参见 SiteMapper工具 [ ^ ]。特别参见SiteMapper.cs中的TraverseWebSite_BW_DoWork。
See SiteMapper Tool[^]. See especially the tread TraverseWebSite_BW_DoWork in SiteMapper.cs.


这篇关于如何从网址获取所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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