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

Source: Internet
Author: User

Find a lot of information on the Internet, PHP is much more, and then found a CSV file. The processing is very troublesome, the foreign site speed is very 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 (Myresponsestream, 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 use F12 to find it first. Then use the tool to find, specific documents 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.