简体   繁体   English

Scrapy response.xpath无效的语法

[英]Scrapy response.xpath Invalid Syntax

I am trying to pull pricing information from a website (learning how to build a webcrawler for practice). 我正在尝试从网站上获取价格信息(了解如何为实践构建网络抓取工具)。 I am using scrapy to build my crawler and in my prices spider I am attempting to pull the xpath for the html field for prices with the following line of code: 我正在使用scrapy构建我的搜寻器,并且在价格蜘蛛中,我尝试使用以下代码行为价格的html字段提取xpath:

text = response.xpath(‘/html/body/div[8]/div[2]/div[1]/div[2]/div[4]/div[7]/div[1]/div/meta[2]’).extract()

When I run the program I am getting "Syntax Error: Invalid Syntax" with a carrot under the first single quote in response.xpath(). 当我运行程序时,我在response.xpath()的第一个单引号下得到了一个带有胡萝卜的“语法错误:无效的语法”。 I have tried changing to double quotes which changed nothing. 我曾尝试将双引号更改为不变。 Any ideas? 有任何想法吗?

这是您使用的引号类型,请使用'或“”,而不是'

text = response.xpath('/html/body/div[8]/div[2]/div[1]/div[2]/div[4]/div[7]/div[1]/div/meta[2]').extract()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM