python - aria-label 的 Python Scrapy 提取值
问题描述
我是 Scrapy 的新手,我正在尝试抓取一个在类上有 aria-label 的页面:
<body>
<div class="item-price" aria-label="$1.99">
.....
</div>
</body>
我正在尝试在我的蜘蛛上使用以下解析来提取标签:
def parse(self, response):
price = circular_item.css("div.item-price > aria-label::text").extract()
yield price
当我运行蜘蛛时,我收到以下错误:
2018-09-02 18:34:03 [scrapy.core.scraper] ERROR: Spider must return Request, BaseItem, dict or None, got 'list' in <GET https://example.com/test.html>
如何在这里提取 aria-label 的值?
解决方案
您的代码中有几个错误:
def parse(self, response):
item = {}
item["price"] = response.xpath('//div[@class="item-price"]/@aria-label').extract_first()
yield item
推荐阅读
- python - += 运算符可以在 Python 中的单行 if 语句中使用吗?
- ios - 使用 URL 链接导入新的 Siri 快捷方式
- javascript - 如何使用 Cheerio 获取锚标记的 innerHTML?
- hive - 如何避免用户从 hive 元存储中运行 drop delta table
- go - 是否可以通过查询区分同一路径上的路线?
- cordova - 使用带有链接的 Cordova SocialSharing 插件将图像分享到 Facebook
- python-3.9 - AttributeError:“Stockfish”对象没有属性“stockfish”
- swift - 如何在while循环spritekit内部生成之前等待
- kubernetes - 使用 Image Transformer 仅更改 Kustomize Overlay 中的图像名称/注册表
- php - IIS HTTP-Fehler 500.19 - 内部服务器错误