scrapy-移動號碼

import scrapy
class PhoneSpider(scrapy.Spider):
	name="phone"
	start_urls=[
	 'https://www.jihaoba.com/escrow/'
]
	def parse(self,reponse):
		for li in reponse.xpath("//div[@class='tj_hm']/ul/li"):
			phone=li.xpath('a/@href').re("\\d{11}")[0]
			price=li.xpath('a/span[@class="tj03"]/text()').extract_first()[1:]
			if price.endswith('萬'):
				price=int(float(price[:-1])*10000)
			else:
				price=int(price)
			yield{
			"phone":phone,
			"price":price
			}
		next=""http://www.jihaoba.;com"+response.xpath("//a[@class='m-pages-next']/@href").extract_first()			
		yield scrapy.Request(next)
     					
			
	
from scrapy import cmdline

cmdline.execute("scrapy crawl phone -o info.csv -t csv".split())
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章