java意外的标识符_SyntaxError:带有xpath的意外标识符(SyntaxError: Unexpected identifier with xpath)...

SyntaxError:带有xpath的意外标识符(SyntaxError: Unexpected identifier with xpath)

我正在学习xpath,我正在尝试从html usint xpath获取一些数据

我发现谷歌浏览器有一个“复制xpath”的选项,它很好用

但对这个例子不起作用

some divs

我在谷歌Chrome控制台上使用它

$x("//*[@id="site-main"]/header")

并返回“SyntaxError:Unexpected identifier”我没有看到任何错误......是吗?

i am learning xpath, and i am trying to get some data from html usint xpath

i found that google chrome has a option to "copy xpath" and it works nice

but doesnt work to this exemple

some divs

i use this on google chrome console

$x("//*[@id="site-main"]/header")

and return "SyntaxError: Unexpected identifier" i dont see anythin wrong...do you?

原文:https://stackoverflow.com/questions/20099681

更新时间:2020-01-10 23:44

最满意答案

$x("//*[@id="site-main"]/header")

^ ^

标记的引号会导致错误 - 实际上,字符串在=之后立即终止。

您必须转义XPath表达式中的引号。 转义的方式取决于您使用的语言。 如果它是Javascript,那么它将是\ :

$x("//*[@id=\"site-main\"]/header")

$x("//*[@id="site-main"]/header")

^ ^

The marked quotes cause the error — in fact, the string is terminated right after =.

You have to escape the quotes inside the XPath expression. The way of escaping depends on the language you are using. If it's Javascript, then it would be with \:

$x("//*[@id=\"site-main\"]/header")

Also have a look on this question: Escape quotes in JavaScript

2017-05-23

相关问答

getJSON为您解析JSON - 调用$.parseJSON会将该对象转换为字符串[object Object] ,然后尝试解析该错误。 只需省略$.parseJSON调用并直接使用data 。 此外,我应该注意到,对array_push的调用是奇怪且不必要的。 array_push通常需要一个数组和一个值来推动它,但是(例如)在你的第一行中,你将$return['amount']为"$amount" ,然后将$return['amount']传递给array_push ,它什么也不做,最糟糕的

...

$('#savetickets-list').append('\

\

' + ticketname + '

\
\

');

当你想在JS中编写多行字符串时,你必须转义新行。 $('#savetickets-list').append('\

\

...

从函数参数中删除int类型: function edades(min, max){

var edades = [22,27,29];

var num=0;

var i;

for (i = 0; i < edades.length; i++) {

if(min<=edades[i] && edades[i]<=max){

num++;

}

}

return num;

}//edades

...

您的JavaScript函数调用将导致Unexpected identifier语法错误。

单击该按钮时,将执行以下JavaScript并导致错误。 getLessons(Career Services Assignments)

你想要将函数参数变成一个字符串,就像你通常在JavaScript中一样; 通过将内容包装在引号字符中。 (选择单引号,因为我们将把调用嵌入到HTM

...

由于您不提供任何停止条件,因此可以用无限循环替换setInterval // promisified "setTimeout" to use later

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

(async function example() {

let driver = await new Builder().forBrowser('firefox').setFirefoxOptions

...

$x("//*[@id="site-main"]/header")

^ ^

标记的引号会导致错误 - 实际上,字符串在=之后立即终止。 您必须转义XPath表达式中的引号。 转义的方式取决于您使用的语言。 如果它是Javascript,那么它将是\ : $x("//*[@id=\"site-main\"]/header")

另请看这个问题: JavaScript中的Escape引号 $x("//*[@id="site-main"]/header")

...

当您添加代码οnclick='statusUpdate("+obj[i].toString()+");' , obj [i]是一个对象,并且调用toString()会返回一个字符串“[object Object]”而不是一个序列化对象。 JSON.stringify(testeObj)

要么 obj={

'userId':userId,

'companyId':companyId,

'groupId':groupId,

'keywordSearch':'"'+ke

...

我找到了解决方案! 非常感谢帮助我的人:D。 我需要根据选择的单选按钮显示monthly_price ,因此我将每个按钮的id属性设置为for循环中rs[0]中该特定元素的rs[0] 。 然后我获得了该属性的值,并将我想要更改的文本设置为等于showPrice()中的值。 以下是代码。

function showPrice() {

$("#servicePriceString").text($('input[name=selectedService]:c

...

在JS类中定义方法时,不需要使用function关键字。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes 你可以干脆做。 class hello {

helloworld () {

console.log('helloworld');

}

}

var a = new hello();

a.helloworld();

//to export from file

e

...

Mongorito不使用生成器( 不再 ),这意味着你不能使用yield (即便如此,你得到的错误是因为yield只在生成器函数中有效,但是你在你的顶层使用它码)。 它现在使用承诺。 如果您愿意使用Node v7(或像Babel这样的转换器 ),您可以使用async/await 。 您的代码看起来像这样: const Mongorito = require('mongorito');

const Model = Mongorito.Model;

const Users = Mode

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值