gpt4 book ai didi

xpath - 使用 YQL 多查询和 XPath 解析 HTML,如何转义嵌套引号?

转载 作者:行者123 更新时间:2023-12-03 15:37:33 25 4
gpt4 key购买 nike

标题比它必须的更复杂,这是问题查询。

SELECT * 
FROM query.multi
WHERE queries="
SELECT *
FROM html
WHERE url='http://www.stumbleupon.com/url/http://www.guildwars2.com'
AND xpath='//li[@class=\"listLi\"]/div[@class=\"views\"]/a/span';
SELECT *
FROM xml
WHERE url='http://services.digg.com/1.0/endpoint?method=story.getAll&link=http://www.guildwars2.com';
SELECT *
FROM json
WHERE url='http://api.tweetmeme.com/url_info.json?url=http://www.guildwars2.com';
SELECT *
FROM xml
WHERE url='http://api.facebook.com/restserver.php?method=links.getStats&urls=http://www.guildwars2.com';
SELECT *
FROM json
WHERE url='http://www.reddit.com/button_info.json?url=http://www.guildwars2.com'"

特别是这条线,
xpath='//li[@class=\"listLi\"]/div[@class=\"views\"]/a/span'

由于引用,这是有问题的,我必须将它们嵌套三层深,而且我已经用完了引号字符来使用。我尝试了以下变体但没有成功:
//no attribute quoting
xpath='//li[@class=listLi]/div[@class=views]/a/span'

//try to quote attribute w/ backslash & single quote
xpath='//li[@class=\'listLi\']/div[@class=\'views\']/a/span'

//try to quote attribute w/ backslash & double quote
xpath='//li[@class=\"listLi\"]/div[@class=\"views\"]/a/span'

//try to quote attribute with double single quotes, like SQL
xpath='//li[@class=''listLi'']/div[@class=''views'']/a/span'

//try to quote attribute with double double quotes, like SQL
xpath='//li[@class=""listLi""]/div[@class=""views""]/a/span'

//try to quote attribute with quote entities
xpath='//li[@class="listLi"]/div[@class="views"]/a/span'

//try to surround XPath with backslash & double quote
xpath=\"//li[@class='listLi']/div[@class='views']/a/span\"

//try to surround XPath with double double quote
xpath=""//li[@class='listLi']/div[@class='views']/a/span""

都没有成功。

我没有看到太多关于转义 XPath 字符串的内容,但我发现的所有内容似乎都是使用 concat(这无济于事,因为 ' 和 "都不可用)或 html 实体的变体。不使用引号作为属性不会不会抛出错误但失败,因为它不是我需要的实际 XPath 字符串。

我在 YQL 文档中没有看到有关如何处理转义的任何内容。我知道这是多么的边缘案例,但希望他们有某种逃脱指南。

最佳答案

您需要使用 来转义任何分隔 XPath 查询的字符。双反斜杠 ... 换句话说:

SELECT * FROM query.multi 
WHERE queries="
SELECT *
FROM html
WHERE url='http://www.stumbleupon.com/url/http://www.guildwars2.com'
AND xpath='//li[@class=\\'listLi\\']/div[@class=\\'views\\']/a/span';
SELECT *
FROM xml
WHERE url='http://services.digg.com/1.0/endpoint?method=story.getAll&link=http://www.guildwars2.com';
SELECT *
FROM json
WHERE url='http://api.tweetmeme.com/url_info.json?url=http://www.guildwars2.com';
SELECT *
FROM xml
WHERE url='http://api.facebook.com/restserver.php?method=links.getStats&urls=http://www.guildwars2.com';
SELECT *
FROM json
WHERE url='http://www.reddit.com/button_info.json?url=http://www.guildwars2.com'"

( try this in the YQL console )

关于xpath - 使用 YQL 多查询和 XPath 解析 HTML,如何转义嵌套引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2932695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com