Python3----Scrapy (note)

Source: Internet
Author: User

1 Importscrapy2 ImportSYS3 #Import IO4 #sys.stdout = io. Textiowrapper (Sys.stdout.buffer, encoding= ' gb18303 ')5  fromScrapy.selectorImportSelector, Htmlxpathselector6 classChoutispider (scrapy. Spider):7Name ='Chouti'8     #allowed_domains = [' chouti.com ']9Start_urls = ['http://dig.chouti.com/']Ten  One     defParse (self, response): A         #print (Response.text) -         #content = str (response.body, encoding= ' utf-8 ') -         #Print (content) the         #HxS = Selector (response=response). XPath ('//a '). Extract () -         #For i in HxS: -         #print (i) -         #HxS = Selector (response=response). XPath ('//div[@id = ' content-list ']/div[@class = ' item '] '). Extract () +         #For i in HxS: -         #print (i) +HxS = Selector (response=response). XPath ('//div[@id = "Content-list"]/div[@class = "item"]')#Label pair image list A          forObjinchHxS: atA = Obj.xpath ('.//a[@class = "Show-content color-chag"]/text ()'). Extract_first () -             Print(A.strip ()) -  - " " - //To show the Descendants - .//The descendants of the current pair of images in /Son - /div the div tag in the son to /div[@id = div tag in "I1" Son and Id=i1 + obj.extract () Each object in the list is converted to a string =>[] - Obj.extract_first () Each object in the list is converted to a string, the first element of the list the //div/text () Gets the text of a label

Python3----Scrapy (note)

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.