. NET Novice crawler teaching, easy to understand.

Source: Internet
Author: User
Tags asin

These two days nothing research crawler, found a lot of processing methods, but I use the most handy is nsoup this bag.

Let me share with you the data I crawled on Amazon. I wrote it with the WebForm, and it was the same with WinForm. Share the code I wrote today. I hope to get some pointers on what to play.

New System.Net.CookieContainer ();    void button1_click (objectString htnmstr = Getpost.get (this). Tbcode.text = htnmstr;}      

The above is to download the entire Web page information, this code online has a lot of open source, I am here to write a class.

 Protectedvoid Button2_Click (Objectsender, EventArgs e) {NSoup.Nodes.Document Htmldoc = NSoup.NSoupClient.Parse (This. Tbcode.text); NSoup.Select.Elements ele = NSoup.NSoupClient.Parse (Tbcode.text). Getelementsbyclass ("S-result-item"); System.Text.StringBuilder SB =NewStringBuilder (); Sb. Append ("<ul>");for (int i =0; I < Ele. Count; i++) {String Xingji = Ele[i]. Select (". A-icon-alt"). Html ();String Shuliang=ele[i]. Select (". a-span5"). Select (". A-spacing-mini"). Select ("A"). Select (". a-size-small"). Html (); Regex reg =New Regex ("[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*"); Match match =Reg. Match (Xingji); Regex REG1 =New Regex ("^\\d+ (, \\d+) *$"); Match Match1 =Reg1. Match (Shuliang); Sb. Append ("<li> title:"+ ele[i]. Select (". a-size-medium"). Html () +"</br> Product Pictures:"+ ele[i]. Select (". s-access-image"). Attr ("Src") +"</br> Seller Name:"+ ele[i]. Select (". a-fixed-left-grid-col"). Select ("Span"). Eq (1). Html () +"</br> Main map Address:"+ ele[i]. Select (". a-link-normal"). Attr ("Href ") + " </br> stars:  "+ match + " </br> Reviews Quantity:  "+ match1 + "  </br>asin:< Span style= "COLOR: #800000" > "+ Ele[i]. Attr ( "data-asin") +  "<li>" ); } sb. Append ( "</ul>" Span style= "color: #000000"); Tbelement.text = sb. ToString (); } 

The above code is I crawl Amazon content also have title, store name, product image and other data, through the class name to search. Simple and easy to understand for some people who have just started to see ... I was just getting started, and wouldn't be able to ask me, to discuss together, to study

. NET Novice crawler teaching, easy to understand.

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.