Experience summary 21--crawl Web data, exchange rates, Htmlagilitypack

Source: Internet
Author: User

Find a lot of information on the Internet, PHP more, and then find a CSV file, processing is very troublesome, foreign sites slow.

Finally, to fetch data on the page, I grabbed from the Bank of China, you can go to other sites crawl.

1. Analog Request URL.

String url = "http://srh.bankofchina.com/search/whpj/search.jsp?pjname=1316";

HttpWebRequest request = webrequest.create (URL) as HttpWebRequest;
                request. Method = "GET";
                request. ContentType = "text/html; Charset=utf-8 ";
                request. useragent = "mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) gecko/20100101 firefox/30.0 ";
                HttpWebResponse response = Request. GetResponse () as HttpWebResponse;
                Stream Myresponsestream = response. GetResponseStream ();
                StreamReader mystreamreader = new StreamReader (Myresponsestrea M, Encoding.UTF8);
                String result = Mystreamreader.readtoend ();

2, the HTML processing. Use Htmlagilitypack for assistance.

HTMLDocument doc = new HTMLDocument ();
Doc. loadhtml (result);
foreach (Htmlnode node in Doc. Documentnode.selectnodes ("//td"))
{
if (node. InnerText = = "USD")
{
result = node. NextSibling.NextSibling.InnerText;
Break
}
}

Specific data location, you can first use F12 to find, and then use the tool to find, detailed documents themselves to check, this method temporarily get to USD-CNY exchange rate.


Experience summary 21--crawl Web data, exchange rates, Htmlagilitypack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.