Posts

Showing posts with the label xpath

XPATH syntax validator in Python

XPATH syntax validator in Python I develop a crawler with many actions. Many xpaths are involving and for this reason I use a json file for storing. Then crawler start running I would like to make a basic syntax check (before xpath usage) on xpaths and raise error for invalid xpaths. for example: xpath1 = '//*[@id="react-root"]/section' xpath2 = '//*[[@id="react-root"]/section' xpath3 = '//*[@id="react-root"]section' from these xpaths only xpath1 is valid is there any module or regex which does this kind of validation? 1 Answer 1 You can compile the xpath strings with lxml.etree.XPath which will raise an exception if the syntax is incorrect: lxml.etree.XPath >>> import lxml.etree >>> lxml.etree.XPath('//*[@id="react-root"]/section') //*[@id="react-root"]/section >>> lxml.etree.XPath('//*...

How to retieve specific text from a tag without using contains() and xpath?

How to retieve specific text from a tag without using contains() and xpath? <div> <label1>Hulk</label1> <label2>Ironman</label2> Thor </div> How do I get only Thor text without using contains in xpath ? If I try getting text of div it would give me all the 3(Hulk,Ironman,Thor) but I want only Thor. Show how did you try, current and desired output, add tag for your programming language – Andersson Jul 2 at 10:21 Assuming that the typo <label1? is fixed, and that there are no other div s in the document, //div/text() will select Thor . – jsheeran Jul 2 at 10:29 <label1? div //div/text() Thor @jsheeran ,...

How to select element from a list and go to parent and then sibling (by Xpath)

How to select element from a list and go to parent and then sibling (by Xpath) I am trying to find a way to press button that is in the same tr as text with which I can localize specific file that I'd like to download. I'll describe it in details: there is a website that contains many tr. Each tr contains couple child td. These td contain description and download button. I need to localize desired tr by description of its td. Then I'd like to go to td that contains download button for this tr. Descriptions are different but I am interested only in those that contain 'DV' text. There is always couple of them on a website but I'd like to select first. What i've figured out so far is: $x("//*[contains(text(), 'DV')]")[0] And then I have no idea how to go to parent element and then to sibling td that contains download button. HTML looks something like that <tr> <td class='a'>DV some other characters1</td><td class=...

Querying a XML column in SQL Server [closed]

Querying a XML column in SQL Server [closed] I wish to query a XML column in SQL Server. Following is the XML structure: <MessageEnvelope xmlns="http://schemas.xyz.com/messagebus/messageenvelope/1.0" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <CustomField1/> <CustomField2 /> <CustomField3 /> <MessagePayload> <Counterpart xmlns="http://schemas.xyz.com/messagebus/saxotrading/counterpart/1.1"> <CounterpartID>111</CounterpartID> <TaxCountry>65</TaxCountry> <CustomerIdTypeCode>D</CustomerIdTypeCode> </Counterpart> <Counterpart xmlns="http://schemas.xyz.com/messagebus/saxotrading/counterpart/1.1"> <CounterpartID>112</CounterpartID> <TaxCountry>5</TaxCountry> <CustomerIdTypeCode>N</CustomerIdTypeCode> </Counterpart> <Counterpart xmlns=...

Xpath getting numeric value in a table

Image
Xpath getting numeric value in a table I need help, im new to xpath. I want to extract data from a xml below is my xpath. Xml : <td class="pprice" style xpath="1">$4,124,000 </td>==$0 <td class="pprice" style xpath="1">$4,124,000 </td>==$0 Xpath: //table/tbody//tr//td[[@class="pprice"]<1000000] //table/tbody//tr//td[[@class="pprice"]<1000000] How to get price less than 1,000,000 , I always get an error NA. 1,000,000 Please help. 1 Answer 1 You can try something like below :- //td[@class='pprice'][. > 4124000] OR //table/tbody//tr//td[[@class="pprice"][. > 4124000] OR You can use translate keyword of XPath as translate translate(.,translate(., '0123456789,', ''), '') The output will be 4,266,240678,260825,0002,185,000589,0007,789,4723,375,0007,780,0001,972,0002,56...