XPath variables use the $somevariable syntax, which is the $ symbol plus the variable name, and then the parameter variable value is passed when the xpath method is called.
>>> # `$val` used in the expression, a `val` argument needs to be passed
>>> response.xpath('//p[@id=$val]/a/text()', val='images').extract_first()
u'Name: My image 1 '
Reference article: A Concise Guide to XPATH
XPath variables use the
$somevariable
syntax, which is the$
symbol plus the variable name, and then the parameter variable value is passed when thexpath
method is called.I understand that the parameter of
xpath
is also a string, please try it.Scrapy Documentation
This is a
python
statement. Why not use string splicing to splice this expression together?For example