3

如何使用 C# 筛选抓取 HTTPS?

4

5 回答 5

5

您可以使用 System.Net.WebClient 启动 HTTPS 连接,然后拉下页面以进行抓取。

于 2009-12-04T15:31:56.003 回答
5

查看Html Agility Pack

于 2009-12-04T15:33:32.053 回答
4

您可以使用 System.Net.WebClient 来抓取网页。这是一个例子: http: //www.codersource.net/csharp_screen_scraping.html

于 2009-12-04T15:35:10.690 回答
2

如果由于某种原因您在作为 Web 客户端访问页面时遇到问题,或者您想让请求看起来像是来自浏览器,您可以在应用程序中使用 Web 浏览器控件,在其中加载页面并使用来自网络浏览器控件的加载内容的来源。

于 2009-12-04T15:34:00.647 回答
1

这是一个具体(尽管微不足道)的例子。您可以在查询字符串中将船舶名称传递给 VesselFinder,但即使它只找到一艘具有该名称的船舶,它仍会向您显示一艘船舶的搜索结果屏幕。此示例检测到这种情况并将用户直接带到船舶的跟踪地图。

        string strName = "SAFMARINE MAFADI";
        string strURL = "https://www.vesselfinder.com/vessels?name=" + HttpUtility.UrlEncode(strName);
        string strReturnURL = strURL;
        string strToSearch = "/?imo=";
        string strPage = string.Empty;
        byte[] aReqtHTML;


        WebClient objWebClient = new WebClient();
        objWebClient.Headers.Add("User-Agent: Other");   //You must do this or HTTPS won't work
        aReqtHTML = objWebClient.DownloadData(strURL);  //Do the name search
        UTF8Encoding utf8 = new UTF8Encoding();

        strPage = utf8.GetString(aReqtHTML); // get the string from the bytes

        if (strPage.IndexOf(strToSearch) != strPage.LastIndexOf(strToSearch))
        {
            //more than one instance found, so leave return URL as name search
        }
        else if (strPage.Contains(strToSearch) == true)
        {
            //find the ship's IMO 
            strPage = strPage.Substring(strPage.IndexOf(strToSearch)); //cut off the stuff before
            strPage = strPage.Substring(0, strPage.IndexOf("\"")); //cut off the stuff after

        }

        strReturnURL = "https://www.vesselfinder.com" + strPage;
于 2015-10-23T01:32:52.327 回答