Issue
I am selecting elements in scrapy framework using shell. I have used xpath
for selecting elements but I want this to be done using response.css
. Below is the code I am using for xpath
.
//div[@class="topic-hero"]//div/text()
I need the alternative in the form of response.css
Solution
There is no CSS selector equivalent for the XPath text()
node-test, so your XPath //div[@class="topic-hero"]//div/text()
has no exact translation in CSS.
You might use the CSS selector div.topic-hero div
which is the equivalent of the XPath //div[@class="topic-hero"]//div
which will select the entire <div>
element.
e.g.
<div class="topic-hero">
<div>foo<span>bar</span></div>
</div>
The XPath //div[@class="topic-hero"]//div/text()
refers to the text node foo
, whereas the XPath //div[@class="topic-hero"]//div
and the CSS selector div.topic-hero div
both refer to the div
element <div>foo<span>bar</span></div>
Answered By - Conal Tuohy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.