7

extract only one part of xpath scrapy

 3 years ago
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.
neoserver,ios ssh client

extract only one part of xpath scrapy

advertisements

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

Querying the database for the created_at value gives the following output: >> kevin.created_at => Sun, 21 Aug 2016 07:46:26 UTC +00:00 How can I extract only the year from this information? I tried to treat kevin.created_at as a string and see if

How can I extract only text in the python scrapy selector

I have this code site = hxs.select("//h1[@class='state']") log.msg(str(site[0].extract()),level=log.ERROR) The ouput is [scrapy] ERROR: <h1 class="state"><strong> 1</strong> <span> job containing <strong>p

Unable to insert this string in a column. Only one part of the string is inserted

I am using SQL Server 2008. And I am trying to insert a string into a table but only part of the string is inserted. I have checked whether it is a SQL injection risk. How to solve or avoid this problem? insert into tble (col1, col2, col3) values (23

Requiring only one part of the ID before the last underscore

Realizing now that I also want to separate out and get all the characters BEFORE "chkOut" GridView1__ctl2_chkOut So I want GridView1__ctl2_ My original question: Needing to get only part of the ID everything after last underscore The LOOP answer

Execute if / else script with only one part of a URL

I am trying to edit my Javascript to pull different data via an AJAX call based upon only part of a URL. Currently, my if/else script looks like this: if (window.location.href=="london") { $.ajax({ url: '../financial-reports/outwork-vs-expenses-

View a SQL Datetime column using only one part of the date

For example I have a column with these dates: 2013-05-18 2012-06-25 2012-07-29 2015-08-31 I want to query and return only rows with the year 2012, or month 05. The issue is that I'm not querying for the whole date but part of it. I'm using Entity Fra

jQuery Mobile - Creates only one part of the active foldable widget

does anyone know of a way to make only a certain part of a collapsible widget actually toggle the collapsible part? I have been trying to figure this out for hours and can't seem to get it. Basically, I don't want a whole <li> to trigger the expand/

PHP - Grab of the file, only one part of the name

I have a folder called /attachments, where I store one csv file. However, that csv file is added dynamically, and therefore I don't know it's exact name. I only know that it will always be a .csv file that will start with "stocklist" (for exampl

Regex, extract only one value from the html-encoded string

I'm having trouble extracting some values, here is my expression: flag:(\S+)=\&quot\;?((?:.(?!\&quot?\s+(?:\S+)=|">))+.)\&quot\;? It is merely trying to extract values from an html encoded string. Here is an example that works fine. &l

Iterating on only one part of the list in Python

I have a list in python, that consists of both alphabetic and numeric elements, say something like list = ["a", 1, 2, 3, "b", 4, 5, 6] and I want to slice it into 2 lists, containing numbers that follow the alphabetic characters, so li

How to delete only one part of the parent category form URL - Magento

I don't know if its very simple to do or if it can be done from back-end or by modifying core files. If I have a product in sub-category and if the url looks like this for my test-product http://www.domain.com/pc/subc1/subc2/test-product I would like

Load only one part of an Ember application at a time

I am building an ember app and it is starting to get large. Is there any way to do lazy loading of the ember files so that it does take 10+ seconds to load when the user first hits the site? For example since I have several logically separate modules

Extending a stored procedure (by adding only one part) by using a parameter in SQL Server

I have a 200 line long stored procedure, which gets a parameter 'prmtr', What I want to do is add an "sql part" to my stored procedure, according to my parameter. example: SELECT A.* FROM ( SELECT * FROM table1 ) A IF (my parameter) = a LEFT JOI

Loading a style sheet for only one part of the page in ASP.NET

I am creating a master page that uses Bootstrap.css for its "master page related content only" (website body, header, nav, and footer) however the content itself is coming in through the MainContent Placeholder web control which is wrapped insid

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK