The result of an xpath is {{price}} in Scrapy - xpath

When I try to scrape price list the value that exists is a variable. You could help me with this please.
This is the source code:
<div id="template-precio" type="text/x-handlebars-template" style="display:none">
{{#if potentialSavedPrice}}
<span class="saving">Ahorra <b>${{potentialSavedPrice}}</b></span>
<span class="list">Precio lista: <i>${{price}}</i></span>
<span class="lable">Precio web:</span>
{{#if eCoupon}}
<span class="price">${{potentialCouponPrice}}</span>
<span class="coupon">Usa el cupón <b>{{eCoupon}}</b></span>
{{else}}
<span class="price">${{potentialDiscountedPrice}}</span>
{{/if}}
{{else}}
<span class="lable">Precio web:</span>
<span class="price">${{price}}</span>
{{/if}}
My xpath:
response.xpath('.//*[#class="list"]/i/text()').extract_first()
Result:
'${{price}}'
This is the code in the chrome inspector:
<div class="details-price">
<div class="">
<span class="saving">Ahorra <b>$369.943,87</b></span>
<span class="list">Precio lista: <i>$3.699.438,68</i></span>
<span class="lable">Precio web:</span>
<span class="price">$3.329.494,81</span>
<span class="coupon">Usa el cupón <b>B2BUSINESS</b></span>
This is the page:
http://www3.lenovo.com/co/es/ofertas-y-cupones
Thank you

Related

Bootstrap dropdown-toggle

The dropdown is not showing, I won’t mind any assistance on what I’m doing wrong.
<div class=“boxOptions”>
<div data-toggle=“dropdown” arial-haspopup=“true” arial-expanded=“false”>
<i class=“fas fa-ellipsis-v”></i>
</div>
<div class=“dropdown-menu”>
<a class=“dropdown-item” href=“#”>Activate</a>
<a class=“dropdown-item” href=“#”>Delete</a>
</div>
</div>
Make it like this.
<div class="boxOptions dropdown">
<div data-toggle="dropdown">
<i class='fas fa-ellipsis-v'></i>
</div>
<div class='dropdown-menu'>
<a class='dropdown-item' href='#'>Activate</a>
<a class='dropdown-item' href='#'>Delete</a>
</div>
</div>
Try this one

python scrapy Xpath selecting text() not getting

I have this HTML code:
<div class="copy" style="padding:0px 45px 15px 30px;"><img src="/images/dot_clear.gif" height="1" width="623" border="0" class="">
<span class="copybold">
<span class="">viswa</span>
</span>
<div class="">
<span class="">first value</span><br class="">
<span class="">100-100-1000</span><br class="">
<span class="">2304 street</span><br class="">
<span class="">kannamapet</span>,
<span class="">TN</span>
<span class="">6000002</span><br class="">
</div>
Lic. Num:<span class="">234</span><br class="">
Lic. Year:<span class="">01/01/2001</span><br class="">
Lic. Expiration Year:<span class="">12/31/19</span><br class="">
Certificate approved .
<span class="copybold">
<span class="">Nathan</span>
</span>
<div class="">
<span class="">second value</span><br class="">
<span class="">200-200-2000</span><br class="">
<span class="">2367 street</span><br class="">
<span class="">kannamapet</span>,
<span class="">TN</span>
<span class="">6000002</span><br class="">
</div>
Lic. Num:<span class="">235</span><br class="">
Lic. Year:<span class="">01/01/2002</span><br class="">
Lic. Expiration Year:<span class="">12/31/2012</span><br class="">
Certificate approved .
I'm trying to get Lic. Num value = 234 and 235 and lic year but always showing null or invalid xpath,
I tried with:
//*[contains(text(), 'Num')]
But this is returning null.
Thanks for the help in advance
Use the following xpath.
//span[#class='copybold']/following-sibling::span[1]
Snapshot:
To get 234
//div[#class='copy']/div[#class=''][1]/following-sibling::span[#class=''][1]/text()
To get 235
//div[#class='copy']/div[#class=''][2]/following-sibling::span[#class=''][1]/text()
To get the license numbers:
//span[#class=''][preceding::text()[1][contains(.,'Lic. Num')]]/text()
Output:
234
235
To get the licence years:
//span[#class=''][preceding::text()[1][contains(.,'Lic. Year')]]/text()
Output:
01/01/2001
01/01/2002

How to get href value in using HtmlAgilityPack?

How do I retrieve the values of HREF Tag using HTML AgilityPack?
<div class="row">
<div class="col-sm-24 businessCapsule--ctas">
<a href="http://www.xyz.coo.in" data-tracking="FLE:WL:CLOSED" class="businessCapsule--ctaItem" target="_blank" rel="nofollow noopener">
<div class="icon icon-Business-website" title="Website"></div> Website</a>
<div class="businessCapsule--telephone">
<div class="business--telephone business--telephone-noMarginRight">
<span class="icon icon-phone business--telephoneIcon"></span>
<div class="business--telephoneContent">
<span class="business--telephonePrefix">Tel</span>
<span class="business--telephoneNumber" itemprop="telephone">154 75 695 451 </span>
Try with a.Attributes.First().Value;
Where "a" is the HtmlNode that you want

Displaying diffrerent data from JSON in two separate tabs

I've got two tabs, which have to display data from different films using rotten tomatoes API. My tabs #tab4 and #tab5 have data attributes which contains film id number, like this:
<a href="#" rel="tabs4" id="tab4" data-movie-id="770672122">
Then I got this code, which adds same class to both tabs and $(this) is supposed to show which data attribute should be taken when tab is clicked.
$("#tab4, #tab5").addClass("tab");
$('.tab').click(function(){
var filmID = $(this).attr("data-movie-id");
Then, using this var, I make url in ajax request:
$.ajax ({
dataType: "jsonp",
url: "http://api.rottentomatoes.com/api/public/v1.0/movies/" + filmID + ".json?apikey=[your_api_key]",
success: dataHandler,
crossDomain: true
});
Problem is that only #tab4 content is displayed. Even if I delete addClass and add click function to only #tab5, its data is displayed in the fourth tab content. What am I missing?
HTML:
<li>
<a href="#" rel="tabs4" id="tab4" data-movie-id="770672122">
Tab 4
</a>
</li>
<li>
<a href="#" rel="tabs5" id="tab5" data-movie-id="10591">
Tab 5
</a>
</li>
<div class="tab-content" id="tabs4">
<div class="film">
<div class= "film-info">
<div id="title"></div>
<br>
<div id="year">
<span class="first-word">
Year:
</span>
</div>
<div id="studio">
<span class="first-word">
Studio:
</span>
</div>
<div id="synopsis">
<span class="first-word">
Synopsis:
</span>
</div>
</div>
<div id="poster" class="poster"></div>
</div>
</div>
<div class="tab-content" id="tabs5">
<div class="film">
<div class= "film-info">
<div id="title"></div>
<br>
<div id="year">
<span class="first-word">
Year:
</span>
</div>
<div id="studio">
<span class="first-word">
Studio:
</span>
</div>
<div id="synopsis">
<span class="first-word">
Synopsis:
</span>
</div>
</div>
<div id="poster" class="poster"></div>
</div>
</div>

xpath specific selection with condition

this might be simple, but I would like to select everything within <div class="rc-box-citations-body"> under the condition that it must belong to <div class="definitionBox" id="meaning-1-1">, thereby uniquely identifying it. How can I do that with xpath? Thanks.
<div class="definitionIndent">
<div class="definitionNumber">1.a</div>
<div class="definitionIndent">
<div class="definitionBox" id="meaning-1-1">
<span class="textmedium">
<span class="stampNoBorder">text</span>
<span class="definition">text</span>
</span>
</div>
<div class="definitionBox">
<div class="rc-box-citations">
<div class="rc-box-citations-top">
<span class="rc-citations-north-west"> </span>
<span class="rc-citations-north-east"> </span>
</div>
<div class="rc-box-citations-body"><span class="citat">text</span> <a class="sourcepop" href="javascript:void(0);"><span class="source">text</span><span class="popup">text</span></a></div>
<div class="rc-box-citations-bot">
<span class="rc-citations-south-west"> </span>
<span class="rc-citations-south-east"> </span>
</div>
</div>
</div>
</div>
</div>
If I modify your xml slightly, and take under the condition that it must belong to to mean that is a descendant of.... then this xpath works
//div[#class='definitionBox'][#id='meaning-1-2']//div[#class='rc-box-citations-body']
The XML is
<?xml version="1.0" encoding="utf-16"?>
<div class="definitionIndent">
<div class="definitionNumber">1.a</div>
<div class="definitionIndent">
<div class="definitionBox" id="meaning-1-1">
<span class="textmedium">
<span class="stampNoBorder">text</span>
<span class="definition">text</span>
</span>
</div>
<div class="definitionBox" id="meaning-1-2">
<div class="rc-box-citations">
<div class="rc-box-citations-top">
<span class="rc-citations-north-west"></span>
<span class="rc-citations-north-east"></span>
</div>
<div class="rc-box-citations-body">
<span class="citation">text</span>
<a class="sourcepop" href="javascript:void(0);">
<span class="source">text</span>
<span class="popup">text</span>
</a>
</div>
<div class="rc-box-citations-bot">
<span class="rc-citations-south-west"></span>
<span class="rc-citations-south-east"></span>
</div>
</div>
</div>
</div>
</div>
The tool I used is XPathVisualizer:

Resources