xpath

access #text property of XMLAttribute in powershell

女生的网名这么多〃 提交于 2020-02-03 05:38:04
问题 I have an xml document formated like this: <root> <obj> <indexlist> <index name="NUMD" value="val1" /> <index name="DATE" value="val2" /> </indexlist> </obj> </root> now I'd like to change the value attribute of the index element where name is set to "DATE". I get the attribute like this: $attr = $xml.selectnodes("//obj/indexlist/index[@name='DATE']/@value") I can view the value by typing this: $attr.'#text' but I can't change it: $attr.'#text' = 'foo' The property '#text' cannot be found on

Selenium PHPUnit select element by label text

独自空忆成欢 提交于 2020-02-02 16:12:34
问题 I have the following HTML code snippet: <div class="modal-body" style="max-height: 317px;"> <div class="radio"> <label> <input type="radio" name="template" value="5"> <img src="/img/custom-icons/Monitor.png" style="height: 24px"> First descriptive title <p class="text-muted">Some description text</p> </label> </div> <div class="radio"> <label> <input type="radio" name="template" value="37"> <img src="/img/custom-icons/Monitor.png" style="height: 24px"> Second descriptive title <p class="text

XPath variables in lxml

余生颓废 提交于 2020-02-02 15:33:09
问题 I want to use XPath variables to match a user-defined tag and avoid XPath injection vulnerabilities. I have tried from lxml import etree etree.fromstring('<div><p>Hello</p></div>').xpath('.//$var', var='p') but I get XPathEvalError: Invalid expression What am I doing wrong? 回答1: You cannot use a variable as the node test part of a location step in an expression. It has to be a literal name. But you can use a wildcard and a predicate. The following works: etree.fromstring('<div><p>Hello</p><

XPath variables in lxml

拥有回忆 提交于 2020-02-02 15:32:01
问题 I want to use XPath variables to match a user-defined tag and avoid XPath injection vulnerabilities. I have tried from lxml import etree etree.fromstring('<div><p>Hello</p></div>').xpath('.//$var', var='p') but I get XPathEvalError: Invalid expression What am I doing wrong? 回答1: You cannot use a variable as the node test part of a location step in an expression. It has to be a literal name. But you can use a wildcard and a predicate. The following works: etree.fromstring('<div><p>Hello</p><

Reading a javascript variable's value

淺唱寂寞╮ 提交于 2020-02-02 14:35:08
问题 I want to read the value of a javascript variable using Xpath the js text is as follows: var item_url = 'nahodka_sobaki_prodam_schenkov_labradora_278393584' , item_phone = '994h4ada5cc0f9605334b81edd8a4ad548189hbfea9627bf5beb5cb7c699efh1daha84bda6a8ddec8bd33706bf0bc5h849098' ; I only want item_phone value I tried : $x('//script[contains(.,"item_phone")]/text()')[0] it returns var item_url = 'nahodka_sobaki_prodam_schenkov_labradora_278393584' , item_phone =

Reading a javascript variable's value

与世无争的帅哥 提交于 2020-02-02 14:34:26
问题 I want to read the value of a javascript variable using Xpath the js text is as follows: var item_url = 'nahodka_sobaki_prodam_schenkov_labradora_278393584' , item_phone = '994h4ada5cc0f9605334b81edd8a4ad548189hbfea9627bf5beb5cb7c699efh1daha84bda6a8ddec8bd33706bf0bc5h849098' ; I only want item_phone value I tried : $x('//script[contains(.,"item_phone")]/text()')[0] it returns var item_url = 'nahodka_sobaki_prodam_schenkov_labradora_278393584' , item_phone =

如何匹配包含特定字符串的属性?

泪湿孤枕 提交于 2020-02-02 07:23:18
当属性包含多个单词时,按属性选择节点时遇到问题。 例如: <div class="atag btag" /> 这是我的 xpath 表达式: //*[@class='atag'] 该表达式适用于 <div class="atag" /> 但不适用于前面的示例。 如何选择 <div> ? #1楼 添加到bobince的答案...如果您使用的任何工具/库都使用Xpath 2.0,则也可以执行以下操作: //*[count(index-of(tokenize(@class, '\s+' ), $classname)) = 1] 显然需要count(),因为index-of()返回字符串中与之匹配的每个索引的序列。 #2楼 一个有效的2.0 XPath: //*[tokenize(@class,'\s+')='atag'] 或带有变量: //*[tokenize(@class,'\s+')=$classname] #3楼 编辑 :请参阅bobince的解决方案,该解决方案使用 contains 而不是 start-with ,以及一个技巧,以确保在完整令牌的级别上进行比较(不要将“ atag”模式作为另一个“ tag”的一部分找到)。 “ atag btag”是class属性的一个奇数值,但更是如此,请尝试: //*[starts-with(@class,"atag")] #4楼

XPath函数——字符串函数

时光怂恿深爱的人放手 提交于 2020-02-02 03:49:53
字符串函数主要用来处理字符串。字符串函数主要包括以下:concat(),contains(),normalize-space(),substing(),substring-before(),subsring-after(),translate(). 1、concat() concat()函数用于串连多个字符串。 简单示例: xml: <?xml version="1.0" encoding="UTF-8"?> <root> <e id="1">st</e> <e id="2">nd</e> <e id="3">rd</e> </root> */ /*--> */ xslt: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="gb2312" indent="yes"/> <xsl:template match="/root"> <xsl:for-each select="e"> <xsl:value-of select="concat(@id,.,' ')"/> </xsl:for-each> <

Create function in Google sheet to get my external IP address

眉间皱痕 提交于 2020-02-02 03:42:32
问题 I need to create a function in Google sheet to get my external (public) IP address I tried use function =IMPORTXML("https://api.myip.com","//body") , but this method shows diffrint IP address not my external IP address 回答1: The following solution makes use of a custom menu in the Spreadsheets - function onOpen(e) { SpreadsheetApp.getUi() .createMenu('My Menu') .addItem('Get IP', 'getIP') .addToUi(); } function getIP() { SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().appendRow([JSON

一个简单的接口测试案例

六眼飞鱼酱① 提交于 2020-02-01 20:50:51
比如,我们需要实现百度某一只股票,查询出股票的当前价格和市值 我们查询”600754“这只股票的当前价格和市值 实现步骤如下: 1、导入request库,还需要额外导入lxml库(后面使用的到) import requests #倒入requests库 from lxml import etree #倒入lxml 库(没有这个库,pip install lxml安装) 2、构造请求数据,百度搜索发起请求的数据比较多 cookies = { 'BIDUPSID': '90EF3BD78F53BC8C96DF84CD3854CA2D', 'PSTM': '1578233930', 'BD_UPN': '12314753', 'BAIDUID': '885754C8E6BD7B1A771802631815CC6D:FG=1', 'BDORZ': 'B490B5EBF6F3CD402E515D22BCDA1598', 'BDUSS': 'mxYdVpwOEx0eGJsT3VUYTJXbkZJYWhKSGpQWnlqaVBwMlExTWNNRkR4cWtabHRlSVFBQUFBJCQAAAAAAAAAAAEAAACRJsY