我正在尝试使用 pegination 抓取网页,但回电不解析项目,任何帮助将不胜感激....这里是代码
# -*- coding: utf-8 -*-
import scrapy
from ..items import EscrotsItem
class Escorts(scrapy.Spider):
name = 'escorts'
allowed_domains = ['www.escortsandbabes.com.au']
start_urls = ['https://escortsandbabes.com.au/Directory/ACT/Canberra/2600/Any/All/']
def parse_links(self, response):
for i in response.css('.btn.btn-default.btn-block::attr(href)').extract()[2:]:
yield scrapy.Request(url=response.urljoin(i),callback=self.parse)
NextPage = response.css('.page.next-page::attr(href)').extract_first()
if NextPage:
yield scrapy.Request(
url=response.urljoin(NextPage),
callback=self.parse_links)
def parse(self, response):
for x in response.xpath('//div[@class="advertiser-profile"]'):
item = EscrotsItem()
item['Name'] = x.css('.advertiser-names--display-name::text').extract_first()
item['Username'] = x.css('.advertiser-names--username::text').extract_first()
item['Phone'] = x.css('.contact-number::text').extract_first()
yield item
温温酱
相关分类