【问题标题】:Find the right selector css to crawl a webpage on scrapy在scrapy上找到合适的选择器css来爬取网页
【发布时间】:2019-09-05 21:56:55
【问题描述】:

我正在尝试抓取此网页“https://www.woolworths.com.au/shop/browse/drinks/cordials-juices-iced-teas/iced-teas”以提取产品名称,但我找不到正确的选择器,即使是价格、h1 或标题!我试过了:

response.css(".shelfProductTile-descriptionLink") #for the name product
response.css(".price-cents") # for the price
response.css(".tileList-title") # for the title

我该如何继续?

【问题讨论】:

  • 该数据来自 XHR。大多数现代网站都做类似的事情。
  • 正如我在previous post 中告诉您的,如果您使用正确的用户代理,您将获得一个选择器列表。现在我更习惯使用 xpath 选择器了,所以我无法帮助您使用 css 选择器。

标签: python css web-scraping scrapy web-crawler


【解决方案1】:

内容是从 POST xhr 返回的 json 动态加载的,您可以在浏览器的网络选项卡中找到。

请求转到:

https://www.woolworths.com.au/apis/ui/browse/category

有效载荷:

{"categoryId":"1_9573995","pageNumber":1,"pageSize":24,"sortType":"TraderRelevance","url":"/shop/browse/drinks/cordials-juices-iced-teas/iced-teas","location":"/shop/browse/drinks/cordials-juices-iced-teas/iced-teas","formatObject":"{\"name\":\"Iced Teas\"}","isSpecial":False,"isBundle":False,"isMobile":False,"filters":"null"}

在scrapy使用中的响应:

json.loads(response.body_as_unicode())

【讨论】:

  • 我无法复制您的说明。你能告诉更多你是怎么做到的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-30
  • 2017-07-05
  • 2021-04-17
  • 2021-09-25
相关资源
最近更新 更多