extract only one part of xpath scrapy
source link: https://www.codesd.com/item/extract-only-one-part-of-xpath-scrapy.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
extract only one part of xpath scrapy
I want to extract from a web page information with xpath, but I'm getting the wrong information. In this code below I want to get 100
:
<div class="pricing">
<p class="pricePerUnit">
<p class="pricePerMeasure">
£0.64
<abbr title="per">/</abbr>
100
I want to only get 100
, I tried this but it returns £0.64 100
. But, I just want to retrieve the 100
:
`prices_mesure3 = `response.xpath('//p[@class="pricePerMeasure"]/text()').extract()`
Any help please ?
Xpath support node indexing, so you can just add [last()]
or [2]
to your xpath:
In: response.xpath('//p[@class="pricePerMeasure"]/text()[last()]').extract_first()
Out: u'\n 100 '
Related Articles
How to extract only one year from the created_at column
How can I extract only text in the python scrapy selector
Unable to insert this string in a column. Only one part of the string is inserted
Requiring only one part of the ID before the last underscore
Execute if / else script with only one part of a URL
View a SQL Datetime column using only one part of the date
jQuery Mobile - Creates only one part of the active foldable widget
PHP - Grab of the file, only one part of the name
Regex, extract only one value from the html-encoded string
Iterating on only one part of the list in Python
How to delete only one part of the parent category form URL - Magento
Load only one part of an Ember application at a time
Extending a stored procedure (by adding only one part) by using a parameter in SQL Server
Loading a style sheet for only one part of the page in ASP.NET
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK