from selenium import webdriver # 使用chromedriver必需 from scrapy import Selector # 使用Selector import time # TimeSleep休眠 from Interests.models import * #表示models文件处于Interests文件夹下 from selenium.common.exceptions import *
defGet_Url(): broswer.get(domin) sel = Selector(text=broswer.page_source) info = sel.xpath("//ul[@class='clearfix']/li/a/@href").extract() for i in info: product_url = 'https://detail.zol.com.cn' + i print(product_url) url_list.append(product_url)
defGet_Info(): for a in url_list: broswer.get(a) detail = Selector(text=broswer.page_source) # 获取到单个商品的详情页面 name = detail.xpath("//h1/text()").extract()[0] core = detail.xpath("//ul/li[1]/p[1]/text()").extract()[0] radio_core = detail.xpath("//ul/li[1]/p[2]/text()").extract()[0] ram_type = detail.xpath("//ul/li[2]/p[1]/text()").extract()[0] max_ram = detail.xpath("//ul/li[2]/p[2]/text()").extract()[0] appear_size = detail.xpath("//ul/li[3]/p[1]/text()").extract()[0] broad_type = detail.xpath("//ul/li[3]/p[2]/text()").extract()[0] energy_socket = detail.xpath("//ul/li[4]/p[1]/text()").extract()[0] charge_mode = detail.xpath("//ul/li[4]/p[2]/text()").extract()[0]