xpath 相关问题

XPath的主要目的是解决XML文档的各个部分。它还提供操纵弦乐,数字和布尔值的基本设施。 XPath使用紧凑的非XML语法。 XPath在XML文档的抽象逻辑结构上运行,而不是表面语法。

如何在WebdriverIO中获取元素完整的lxpath?

我有代码检查容器下是否显示具有特定文本的元素。 它工作得很好,虽然我使用了完整的 xpath,但是在我们更改选择器之后(它仍然得到......

回答 1 投票 0

Kotlin/Native Cinterop 与 libxml2 - 损坏的 XPath 表达式

版本 科特林 1.9.22 libxml 2.9.14+dfsg-1.3 操作系统:Ubuntu 23.10 问题 在一个小型 Kotlin/Native 应用程序中,我使用 cinterop 和 libxml2 来评估一组 XPath 表达式以提取元素

回答 1 投票 0

使用 document.evaluate() 选择包含撇号的 HTML 元素

我正在尝试使用 document.evaluate() 选择一个包含 1'000 g 的元素。问题是撇号。我尝试使用 \u0027、''、\'、\' 和 ',但它们要么触发无效的 xpath

回答 1 投票 0

在Python中使用xpath和selenium选择HTML元素

感谢您让我在这里提出问题。我是 Selenium 和 XPath 的新手,只是想使用 Python 抓取一个不太简单的网站。 我的问题是: 您对我的具体问题有答案吗...

回答 2 投票 0

Javascript - 验证 xpath 是否存在:$x 与 document.evaluate?

我需要验证网页上的特定元素是否存在。我只需要 true/false、null/string、0/1 或类似的响应。当我用谷歌搜索这个时,我找到的所有解决方案都使用 document.evaluate (并且...

回答 1 投票 0

使用属性名称从 simplexml_load_string 中提取 xml 元素

我想从下面提到的属性名称(sm_field_base_url)或xpath上的XML bsed中提取sm_field_base_url。我怎样才能做到这一点。 我正在使用 simplexml_load_string() 来解析 xml

回答 1 投票 0

从下一个父节点查找特定节点

我正在准备一个 C# 应用程序,其中我必须处理 xml 内容。 我正在准备一个 C# 应用程序,其中我必须处理 xml 内容。 <Document> <SW.Blocks.FC ID="0"> <ObjectList> <SW.Blocks.CompileUnit ID="4" CompositionName="CompileUnits"> <AttributeList> <NetworkSource> <StructuredText xmlns="http://www.siemens.com/automation/Openness/SW/NetworkSource/StructuredText/v3"> <NewLine Num="2" UId="116" /> <Access Scope="GlobalVariable" UId="117"> <Symbol UId="118"> <Component Name="TP40" UId="119" /> <Token Text="." UId="120" /> <Component Name="IN" UId="121" /> <Token Text="." UId="122" /> <Component Name="StopSeg" UId="123" /> <Address Area="None" Type="Bool" BlockNumber="3" BitOffset="3024" Informative="true" /> </Symbol> </Access> <Blank Num="29" UId="124" /> <Token Text=":=" UId="125" /> <Blank Num="1" UId="126" /> <Access Scope="GlobalVariable" UId="127"> <Symbol UId="128"> <Component Name="I_TP40B1" UId="129" /> <Address Area="Input" Type="Bool" BitOffset="1026" Informative="true" /> </Symbol> </Access> <Token Text=";" UId="130" /> <NewLine Num="1" UId="131" /> </NetworkSource> </AttributeList> </SW.Blocks.CompileUnit> </ObjectList> </SW.Blocks.FC> </Document> 根据给定的用户输入“StopSeg”,我需要获取名称为“I_TP40B1”的组件节点。有人可以帮我为此编写 XPath 吗?或任何 C# 代码? 您在结构化文本标签中缺少结束正斜杠。我会使用 Xml Linq 库而不是 XPath。请参阅下面的代码以获取示例 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Xml.Linq; namespace ConsoleApp10 { class Program { const string FILENAME = @"c:\temp\test.xml"; static void Main(string[] args) { XDocument doc = XDocument.Load(FILENAME); XElement symbol = doc.Descendants().Where(x => x.Name.LocalName == "Symbol").FirstOrDefault(); XNamespace ns = symbol.GetDefaultNamespace(); XElement component = symbol.Element(ns + "Component"); string name = (string)component.Attribute("Name"); } } }

回答 1 投票 0

获取属性值并设置为变量

我是机器人框架的新手。我想获取一个值并将其设置为变量。该值是订单金额,每次都会不同。我成功地创建了这个 xpath,其数量与以往相同...

回答 1 投票 0

为什么 RSelenium 无法找到我的 xpath?

我必须在网站上反复执行搜索(https://franklin.genoox.com/clinical-db/home) 很久以前,我发现了 Rselenium 包,并且我之前已经成功使用过它(Af...

回答 1 投票 0

用python解析arxml文件

我有一个需要解析的文件,我需要信息。解析的顺序很重要。 我可以解析文件并获取信息,但不能按顺序解析。 我如何解析这些信息<...

回答 1 投票 0

为什么 XPath 返回的元素比我预期的要多?

为什么 //div["someClass"]/p[1] 也使用 XPath 返回未包装在请求的 div 元素中的 p 标签?只有 //*/div["someClass"]/p[1] 返回带有 exa 的预期结果...

回答 1 投票 0

如何使用 XSLT 和 Xpath 对 XML 进行排序

我需要根据元素的属性对 XML 文件进行排序。 该文件与此类似 我需要根据元素的属性对 XML 文件进行排序。 该文件与此类似 <employees> <employee firstname="Mary" lastname="Poppins" age="30" hobby="Flying"/> <employee firstname="Captain" lastname="Hook" age="40" hobby="Crocodile hunting"/> <employee firstname="Thomas" lastname="Tankengine" age="102" hobby="Steam trains"/> <employee firstname="Ant" lastname="Man" age="37" hobby="hero"/> <employee firstname="Peter" lastname="Pan" age="13" hobby="Flying"/> 我需要按姓氏对员工进行排序,以便 xml 看起来像这样 <employees> <employee firstname="Captain" lastname="Hook" age="40" hobby="Crocodile hunting" /> <employee firstname="Ant" lastname="Man" age="37" hobby="hero" /> <employee firstname="Peter" lastname="Pan" age="13" hobby="Flying" /> <employee firstname="Mary" lastname="Poppins" age="30" hobby="Flying" /> <employee firstname="Thomas" lastname="Tankengine" age="102" hobby="Steam trains" /> </employees> 我尝试了各种示例并查看了 stackoverflow,但我显然错过了一些基本的东西。 这是我最新的尝试 xsl:应用模板 ” xsl:复制/ 正确的模板是 <xsl:template match="employees"> <xsl:copy> <xsl:apply-templates select="employee"> <xsl:sort select="@lastname"/> </xsl:apply-templates> </xsl:copy> </xsl:template> 然后您需要确保设置了身份转换,当前版本的 XSLT 3.0 是 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"> <xsl:output method="xml" indent="yes"/> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="employees"> <xsl:copy> <xsl:apply-templates select="employee"> <xsl:sort select="@lastname"/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet>

回答 1 投票 0

为什么我可以用 Xpath 找到第一个元素,但找不到第二个元素?

我正在尝试在 Selenium Webdriver 中构建一个测试来检查具有相同类名的 2 个 div 的值。 例如,HTML: 我正在尝试在 Selenium Webdriver 中构建一个测试来检查具有相同类名的 2 个 div 的值。 例如,HTML: <div class="prod-card"> <div class="prices"> <div class="price-wrap"> From: <div class="price">$9.99</div> </div> <div class="price-wrap"> To: <div class="price">$19.99</div> </div> </div> </div> 我一直在尝试使用 Selenium 的 Xpath 定位器,但似乎无法找到第二个 div。 例如,以下有效: let lowerPrice = await driver.findElement(By.xpath("//div[@class='price'][1]")).getText(); lowerPrice = lowerPrice.trim(); assert.equal(lowerPrice, expectations[i].lowerPrice); 但这不起作用: let higherPrice = await driver.findElement(By.xpath("//div[@class='price'][2]")).getText(); higherPrice = higherPrice.trim(); assert.equal(higherPrice, expectations[i].higherPrice); 我收到错误NoSuchElementError: Unable to locate element: //div[@class='price'][2] 我不知道为什么在找到第一个元素时效果很好,但在找到第二个元素时却不起作用。 有人知道为什么吗? 我宁愿使用 //div[@class='price-wrap'][1]/div[@class='price'] 和 //div[@class='price-wrap'][2]/div[@class='price'] 原因是因为 XPath 表达式 //div[@class='price'][2] 试图选择整个 HTML 文档中类名为“price”的第二个 div 元素,而不是特定上下文中类名为“price”的第二个 div 元素。

回答 1 投票 0

无法在子 div xpath 上找到元素

<div class="gwt-Label WLFP WEEP" data-automation-id="promptOption" id="promptOption-gwt-uid-2" data-automation-label="Start" title="Start" aria-label="Start" role="link" tabindex="0">Start</div> 在我们的应用程序中,搜索后我们得到一堆搜索结果,这些结果基本上都是可点击的链接,我试图找到搜索文本,例如上面示例中的“开始”,然后单击它。 我的 xpath //div[@data-automation-id='promptOption']/ 突出显示该区域,但之后当我提供所需的文本路径时,它找不到该区域。 //div[@data-automation-id='promptOption']//span[contains(@text, 'Start')] //div[@data-automation-id='promptOption' and text()='Start'] //div[@data-automation-id="promptOption"]//a[.='Start'] 您需要: //div[@data-automation-label="Start"]

回答 1 投票 0

如何解决在 Odoo 中打开 Studio 应用程序时出现错误?

我以管理员身份登录时遇到以下问题: 我可以访问联系人模块及其中的记录。 当我尝试在联系人模块中打开 Studio 应用程序时,没有任何反应。它没有

回答 1 投票 0

重新排列层次结构 - 将所有显示为元素 para 的后续兄弟元素的 <list>(及其内容)移动到 para

我需要重新排列层次结构。将出现在 para(如下同级)之后的列表(及其内容)移动到 para 内部,同时将其余数据保留在当前位置。

回答 1 投票 0

重新排列层次结构 - 将元素的后续同级元素移动到该元素末尾之前

我需要重新排列层次结构(移动出现在段落后面、段落内部的列表): 来自: ... ... 我需要重新排列层次结构(移动出现在段落后面、段落内部的列表): From: <para updated="20240205"><text> ... </text> ... </para><list type="num"> ... </list> To: <para updated="20240205"><text> ... </text> ... <list type="num"> ... </list></para> 备注: DTD 允许 para 包含列表,列表也可以包含 para 该段落后面可能有多个列表需要移动到前一个段落的末尾 我对 XSL 比较陌生,不确定如何处理这个问题,因为它们目前是兄弟姐妹 我还没有尝试任何事情,因为我不知道如何解决这个问题。 谢谢 使用例如 <xsl:template match="*[para]"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:for-each-group select="*" group-starting-with="para"> <xsl:choose> <xsl:when test="self::para"> <xsl:copy> <xsl:apply-templates select="@*, node(), tail(current-group())"/> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> 我认为 tail 是 XPath 3/XSLT 3,因此如果您确实使用 XSLT 2 处理器,请改用 subsequence(current-group(), 2)。 当然,推动一切通过apply-templates假设您已经为不想更改的节点设置了身份转换(模板),并为您想要更改的节点上的任何转换添加了模板。

回答 1 投票 0

无法通过 XPATH Selenium Python 定位可点击元素

我尝试单击下拉菜单,然后单击菜单中的特定值。我正在使用浮动范围菜单 https://buff.163.com/goods/769563?from=market#tab=buying&page_num=1。我已经

回答 1 投票 0

从 ASX 抓取当前股价数据

我正在尝试将当前股价数据从 ASX 抓取到 Google 电子表格中。 我没有使用 =googlefinance("ASX.NEA","price") 作为即时延迟价格

回答 2 投票 0

如何从 HTML 段中提取名称“Terence Crawford”,不包括 Span 元素?

我目前在从 HTML 段检索名称“Terence Crawford”时遇到困难。挑战在于排除存在于同一父元素中的 span 元素。 我目前在从 HTML 片段中检索姓名“Terence Crawford”时遇到困难。挑战在于排除存在于同一父元素中的 span 元素。 <td colspan="3" style="position:relative;" class="defaultTitleAlign"> <h1 style="display:inline-block;margin-right:5px;line-height:30px;"> <span style="font-weight:bold;"><i class="fas fa-crown" style="color:#f6b501 !important;"></i></span> "Terence Crawford" </h1> <div style="width:100%;position:relative;margin-top:5px;"> </div> </td> 我尝试通过指定类属性“defaultTitleAlign”和样式属性“display:inline-block;margin-right:5px;line-height:30px;”来检索名称,但它只返回“/n”的真实姓名。即使定位 h1 元素的全部内容,也不会显示名称。 In [9]: response.xpath("//td[@class='defaultTitleAlign']/h1/text()").get() Out[9]: '\n ' 您可以使用 getall() 方法从给定的选择器中收集所有 text() ,然后您可以在返回的列表中找到您要查找的部分。 例如: In [1]: from scrapy.selector import Selector In [2]: html = """<td colspan="3" style="position:relative;" class="defaultTitleAlign"> ...: <h1 style="display:inline-block;margin-right:5px;line-height:30px;"> ...: <span style="font-weight:bold;"><i class="fas fa-crown" style="color:#f6b501 !important;"></i></span> ...: "Terence Crawford" ...: </h1> ...: <div style="width:100%;position:relative;margin-top:5px;"> ...: </div> ...: </td>""" In [4]: response = Selector(text=html) In [5]: text_list = response.xpath("//td[@class='defaultTitleAlign']/h1//text()").getall() In [6]: text = text_list[1].strip() In [7]: text Out[7]: '"Terence Crawford"'

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.