xpath

Most Pythonic way to find the sibling of an element in XML

青春壹個敷衍的年華 提交于 2021-02-10 06:06:54
问题 Problem: I have the following XML snippet: ...snip... <p class="p_cat_heading">DEFINITION</p> <p class="p_numberedbullet"><span class="calibre10">This</span>, <span class="calibre10">these</span>. </p> <p class="p_cat_heading">PRONUNCIATION </p> ..snip... I need to search the totality of the XML, find the heading that has text DEFINITION , and print the associated definitions. The format of the definitions is not consistent and can change attributes/elements so the only reliable way of

Reading title tag in svg?

和自甴很熟 提交于 2021-02-10 05:19:30
问题 How do I read the text in below? svg seems to be a special case. Tried the below, but of no help //*[name()='svg']/title //*[name()='svg' and @title='Test'] //*[name()='svg' and contains(@title,'Test')] <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 137 125" version="1.1"> <title>Test</title> <desc>Created with Sketch.</desc> 回答1: To extract the text from the <title> tag within the svg WebElement you can use either of the following Locator Strategies: Using

Grab following siblings in XPath?

谁都会走 提交于 2021-02-10 05:16:40
问题 I am trying to grab the li class text in the following based on the strong tag higher up in the tree containing a certain word, in this case: "restaurants": <p class="">The location, where the condo is situated, offers a good choice of <strong>restaurants</strong>. Some of them are listed below:</p> <ul class=""> <li class="">Restaurant 1</li> <li class="">Restaurant 2</li> <li class="">Restaurant 3</li> <li class="">Restaurant 4</li> <li class="">Restaurant 5</li> </ul> I have tried many

Get Absolute XPath of Web Element

陌路散爱 提交于 2021-02-10 04:20:44
问题 I'm using Javascript in the following code to retrieve the absolute XPath of a web element: public String getAbsoluteXPath(WebDriver driver) { return (String) driver.executeScript( "function absoluteXPath(element) {"+ "var comp, comps = [];"+ "var parent = null;"+ "var xpath = '';"+ "var getPos = function(element) {"+ "var position = 1, curNode;"+ "if (element.nodeType == Node.ATTRIBUTE_NODE) {"+ "return null;"+ "}"+ "for (curNode = element.previousSibling; curNode; curNode = curNode

Get Absolute XPath of Web Element

寵の児 提交于 2021-02-10 04:14:43
问题 I'm using Javascript in the following code to retrieve the absolute XPath of a web element: public String getAbsoluteXPath(WebDriver driver) { return (String) driver.executeScript( "function absoluteXPath(element) {"+ "var comp, comps = [];"+ "var parent = null;"+ "var xpath = '';"+ "var getPos = function(element) {"+ "var position = 1, curNode;"+ "if (element.nodeType == Node.ATTRIBUTE_NODE) {"+ "return null;"+ "}"+ "for (curNode = element.previousSibling; curNode; curNode = curNode

Get Absolute XPath of Web Element

人盡茶涼 提交于 2021-02-10 04:09:15
问题 I'm using Javascript in the following code to retrieve the absolute XPath of a web element: public String getAbsoluteXPath(WebDriver driver) { return (String) driver.executeScript( "function absoluteXPath(element) {"+ "var comp, comps = [];"+ "var parent = null;"+ "var xpath = '';"+ "var getPos = function(element) {"+ "var position = 1, curNode;"+ "if (element.nodeType == Node.ATTRIBUTE_NODE) {"+ "return null;"+ "}"+ "for (curNode = element.previousSibling; curNode; curNode = curNode

Powershell: XPath cannot select when element has “xmlns” tag?

对着背影说爱祢 提交于 2021-02-09 11:55:55
问题 I've got a very simple xml, as below: <?xml version="1.0" encoding="utf-8"?> <First> <Second> <Folder>today</Folder> <FileCount>10</FileCount> </Second> <Second> <Folder>tomorrow</Folder> <FileCount>90</FileCount> </Second> <Second> <Folder>yesterday</Folder> <FileCount>22</FileCount> </Second> </First> Then I have a powershell script to select "Folder" element: [xml]$xml=Get-Content "D:\m.xml" $xml.SelectNodes("//Folder") It outputs: #text ----- today tomorrow yesterday No problem. But if I

VBScript, MSXML and Namespaces

こ雲淡風輕ζ 提交于 2021-02-08 15:32:01
问题 Given the following XML: <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetMsisdnResponse xmlns="http://my.domain.com/"> <GetMsisdnResult> <RedirectUrl>http://my.domain.com/cw/DoIdentification.do2?sessionid=71de6551fc13e6625194</RedirectUrl> </GetMsisdnResult> </GetMsisdnResponse> </soap:Body> </soap:Envelope> I am trying to access the

R: Webscraping various <div>-classes into lists with (sub-)elements

♀尐吖头ヾ 提交于 2021-02-08 11:49:16
问题 I use rvest to scrape this website. It contains data in such a form (simplified): <div class="editor-type">Editors</div> <div class="editor"> <div class="editor-name"><h3>Otto Heath</h3></div> <span class="editor-affiliation">Royal Holloway University of London</span> </div> <div class="editor"> <div class="editor-name"><h3>Kathrin Smets</h3></div> <span class="editor-affiliation">Royal Holloway University of London</span> </div> <div class="editor-type">Associate Editor</div> <div class=

why xpath derived from chrome does not work

隐身守侯 提交于 2021-02-08 11:19:27
问题 I am trying to scrap data from web of science And here is the specific page I am going to work with. Below is the code I use for extract the abstract: import lxml import requests url = 'https://apps.webofknowledge.com/full_record.do?product=WOS&search_mode=GeneralSearch&qid=2&SID=Q1yAnqE4al4KxALF7RM&page=1&doc=3&cacheurlFromRightClick=no' s = requests.Session() d = s.get(url) soup1 = etree.HTML(d.text) And here is the xpath I got through the copy xpath in Chrome: //*[@id="records_form"]/div