【发布时间】:2019-06-27 16:58:45
【问题描述】:
我正在尝试抓取以下网站的所有城市名称: https://www.zomato.com/directory.
我尝试使用以下 xpath。
python
#1st approach:
def parse(self,response):
cities_name = response.xpath('//div//h2//a/text()').extract_first()
items['cities_name'] = cities_name
yield items
#2nd approach:
def parse(self,response):
for city in response.xpath("//div[@class='col-l-5 col-s-8 item pt0 pb5
ml0']"):
l = ItemLoader(item = CountryItem(),selector = city)
l.add_xpath("cities_name",".//h2//a/text()")
yield l.load_item()
yield city
实际结果:抓取 0 个页面并抓取 0 个项目
预计:阿德莱德、巴拉瑞特等
【问题讨论】:
标签: xpath web-scraping scrapy