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)