How to use Date Format Converter in xpath? Refer below XML and x-path for further reference.
XML:
<FORM>
<STRT_DT>2020-01-01</STRT_DT>
</FORM>
X-path I used:
//FORM/STRT_DT/tib:format-date("YYYY-MM-DD",tib:parse-date('DD-Mmm-YYYY'))
Assuming we change your xml to:
<FORM>
<STRT_DT>2020-12-31</STRT_DT>
</FORM>
then this xpath expression
format-date(//FORM/STRT_DT, '[D01]/[M01]/[Y0001]')
EDIT:
or this
string(format-date(//FORM/STRT_DT, '[D01]/[M01]/[Y0001]'))
will output:
31/12/2020
Check this if you want the output in dd/mmm/yyyy format.
string(format-date(//FORM/STRT_DT, '[D01]/[MNn,3-3]/[Y0001]'))
Related
in this HTML using scrapy i can access the full info-car by : './/#info-car' XPath
<div class="car car-root"
info-car='{brand":"BMW","Price":"田"name":"X5","color":null,"}'>
</div>
what is the XPath to pick only the name of info-car ?
You can obtain the name by using a combination of xpath and regex. See below sample code:
response.xpath(".//#info-car").re_first(r'"name":"(.*)",')
Hello I have this HTML:
<div class="_3Vhpd"><span>Your commerce Data</span>
<a class="n3G0C" href='http://www.webadress.......'><span>Some Text</span</a>
</div>
I tried to obtain the tag as follow:
parser.xpath('//div[contains(#class,"_3Vhpd")]//following-sibling::*[a[#class="n3G0C"]]/#href ')
but I received none '[]'. Maybe because is not just after div but after a span...
First, you sample html doesn't have a class="n3G0C", but assuming you fix it, this xpath expression should work:
//div[contains(#class,"_3Vhpd")]//following-sibling::a/#href
Output:
http://www.webadress.......
I'm trying to extract the value of the attribute data-asin-price inside a <div> tag
Which in the example below you can see is 22.63
<div id="cerberus-data-metrics" style="display: none;" data-asin="B079GMRZ8S" data-asin-price="22.63" data-asin-shipping="0.0" data-asin-currency-code="AUD" data-substitute-count="-1" data-device-type="WEB" data-display-code="Asin is not eligible because it is not enabled"></div>
Is there any way to do this using response.xpath() with scrapy?
Thank you
I just wanted to post the answer I found.
To get the 22.63 value our of the data-asin-price attribute in scrapy shell I did the following:
response.xpath('//div[#id = "cerberus-data-metrics"]/#data-asin-price').extract_first()
Cheers
<html>
<body>
Example
SO
<div>
<div class="kekeke">JSAFK</div>
</div>
</body>
</html>
For getting a JSAFK element in this doc, using XPath, can I just write //*div[#class=kekeke] instead full XPath?
// is short for /descendant-or-self::node()/. So...
This XPath,
//div[#class='kekeke']
will select all such div elements in the document:
<div class="kekeke">JSAFK</div>
This XPath,
//div[#class='kekeke']/text()
will select all text nodes under all such div elements in the document:
JSAFK
there is something wrong in "
//*div[#class=kekeke]
you can't use * and div together. if you want to have a shorter path.
you can write like this
//div[#class="kekeke"]/text()
the html is like this:
<div id='id'>
<a href>abc</a>
"xyz"
</div>
I want to use xpath to get the xyz (I use it in capybara), but my xpath can't work
... //div[#id='id'].text
it returns abcxyz
how can I get it?
Text is its own text node, so the correct selector would be:
.//div[#id='id']/text()