Reputation:
I am not able to pass Xpath Expression as a string variable in my Scrapy code. Code below:
def start_requests(self):
urls = [
'http://www.example.com'
]
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
strvar = "'//title'"
print (strvar)
print (response.xpath(strvar))
print (response.xpath('//title'))
The above two response.xpath(xpath expression) queries evaluates to different xpaths as
Selector xpath="'//title'" ....
Selector xpath='//title' ....
Can't figure out where am I going wrong.
Upvotes: 0
Views: 117
Reputation: 473893
You don't need to put the inner quotes, replace:
strvar = "'//title'"
with just:
strvar = "//title"
Upvotes: 1