Reputation: 479
I use the following website to test:
scrapy shell http://example.webscraping.com/places/default/user/login#
And do some test:
Input 1:
response.xpath('//div//[@style]/input')
Output 1:
[<Selector xpath='//div[@style]/input' data='<input name="_next" type="hidden" value='>,
<Selector xpath='//div[@style]/input' data='<input name="_formkey" type="hidden" val'>,
<Selector xpath='//div[@style]/input' data='<input name="_formname" type="hidden" va'>]
Input 2:
response.xpath('//div//@style/input')
Output 2:
[]
Input 3:
response.xpath('//div//@style/input') == response.xpath('//div[style]/input')
Output 3:
True
I want to know how different 1 and 2 is,thanks.
Upvotes: 0
Views: 196
Reputation: 4667
I think that you're looking for this selector:
response.xpath('//div[@style]/input')
This is how it works:
div
elements from the document (//div
);style
attribute ([@style]
);input
nodes which are descendants of the elements selected on step 2 (/input
).Your 2nd selector (//div//@style/input
) wouldn't work well because it does:
div
elements from the page (//div
);style
attribute from every descendant of the divs selected in step 1 (//@style
);input
nodes which are direct descendants of the style
attributes, which is something that doesn't exist (/input
).Upvotes: 2