首页 > 解决方案 > 如何从 xpath 中抓取企业名称并在 csv 中获取文件

问题描述

i am trying to scrape yellow page by using scrapy and python getting all other result right but not getting the business name 

尝试更改 xpath 甚至尝试了 css 选择器但没有得到正确的结果

标签: pythonscrapy

解决方案


如果您谈论的是 yellowpages.com,那么您可以使用带有以下标签的 css 选择器从搜索结果页面中抓取企业名称:'div.info .business-name span::text'

因此,例如,您可以启动一个 scrapy shell 并转到搜索结果:

scrapy shell "https://www.yellowpages.com/search?search_terms=doctors&geo_location_terms=berlin"

然后在你的scrapy shell中输入以下内容:

response.css('div.info .business-name span::text').extract()

您现在应该会收到该特定页面的所有公司名称的列表。

但是请注意,yellowpages.com 在他们的 robots.txt 中明确声明他们的任何页面都不允许使用scrapy。


推荐阅读