【发布时间】:2021-10-29 13:56:52
【问题描述】:
当我运行我的 scrapy 网络爬虫时,它没有按照页面来抓取我代码中的数据。
import scrapy
from ..items import YellowpagesItem
class YSpider(scrapy.Spider):
name = 'yp2'
allowed_domains = ['yellowpages.com']
start_urls = [
'https://www.yellowpages.com/search?search_terms=pizza&geo_location_terms=Conshohocken%2C+PA'
]
def parse(self, response):
for link in response.css('a.businesss-name'):
yield response.follow(link.attrib.get('href'), callback=self.parse_business)
def parse_business(self, response):
item = YellowpagesItem()
item['name'] = response.css('h1::text').get()
item['phone'] = response.css('p.phone::text').get()
item['street'] = response.css('h2 > span::text').get()
item['city_state'] = response.css('div.contact > h2.address::text').get()
item['tags'] = ','.join([item.get() for item in response.css('p.cats > a::text')])
item['email'] = response.css('a.email-business').attrib.get('href')
yield item
【问题讨论】:
标签: python python-3.x web-scraping scrapy