【发布时间】:2021-03-31 02:22:20
【问题描述】:
您好,我正在尝试使用文字抓取工具和爬虫,但是我不明白为什么我的代码没有进入下一页并循环。
import scrapy
from scrapy import*
import scrapy
from scrapy import*
class SpiderSpider(scrapy.Spider):
name = 'spider'
start_urls = ['https://www.thehousedirectory.com/category/interior-designers-architects/london-interior-designers/']
def parse(self, response):
allbuyers = response.xpath('//div[@class="company-details"]')
for buyers in allbuyers:
name = buyers.xpath('.//div/a/h2/text()').extract_first()
email = buyers.xpath('.//p/a[contains(text(),"@")]/text()').extract_first()
yield{
'Name' : name,
'Email' : email,
}
next_url = response.css('#main > div > nav > a.next.page-numbers')
if next_url:
print("test")
url = response.xpath("href").extract()
yield scrapy.Request(url, self.parse)
【问题讨论】:
标签: python web-scraping scrapy scrapy-shell