importxml xpath div如何在没有类和id的情况下获取信息?

利兹

在Google表格中使用Importxml。

当信息不是div类或div id时,如何从中获取“ data-film-id”和“ data-film-release-year” ?:

<div class="react-component film-poster film-poster-193260 poster linked-film-poster -attributed" 

data-component-class="globals.comps.FilmPosterComponent" 
data-film-id="193260" 
data-film-name="The Choice" 
data-poster-url="/film/the-choice-1987/image-150/" 
data-film-release-year="1987" 
data-film-link="/film/the-choice-1987/" 

我可以使用以下方法从网站(其中A1为[ https://letterboxd.com/tag/30-countries-2018/diary/by/added/page/58/])中获取一些信息到Google表格中:

=ImportXML(A1, "//div[contains(@class,'react-component') and contains(@class,'film-poster')]/a/@href")

所以我知道一切正常,但这仅是因为href在其自己的段落中位于该div下面。我的问题是尝试挖掘上面显示的信息。

在该网站上搜索后,我尝试了此操作(除其他事项外),但导致错误。

=ImportXML(A1, "//li[@class='poster-container']//div[not(@id) or not(@class)]")

但这给了我已有的信息,而不是我需要的信息。

可能因为不是班级或ID而无法获取日期?

迭戈

您需要使用属性选择器

=ImportXML(A1, "//div[contains(@class,'react-component') and contains(@class,'film-poster')]/attribute::data-film-id")

因此,在B列中,您可以使用上面的公式来显示胶片ID,在C列中,可以使用另一个发布年份的公式,依此类推。

如果您希望将其全部排成一排,我不建议这样做,那就是

=ImportXML(A1, "//div[contains(@class,'react-component') and contains(@class,'film-poster')]/attribute::data-film-id | //div[contains(@class,'react-component') and contains(@class,'film-poster')]/attribute::data-film-release-year")

我不建议将其组合,因为它会在“年,id,年,id,...”一栏中输出所有内容。很乱。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

IMPORTXML XPath_Query for Google Sheets

IMPORTXML内的XPATH在查询中带有撇号

Google表格中的importxml xpath

XPath,用于在Google表格中使用ImportXML的<address>标记

Google表格和XPath中的IMPORTXML

如何在Steam Workshop上为Google表格的IMPORTXML获取正确的XPath?

Google表格中的ImportXML XPath URL

如何在Google表格中使用IMPORTXML和Xpath捕获<img src> URL?

如何使用IMPORTXML和XPath返回特定的链接地址

Google表格ImportXML XPath返回#N / A

IMPORTXML公式的2个文本之间的Xpath

用于Google importXML函数的XPath查询

如何在Google表格中找出IMPORTXML的正确xpath-N / A错误?

包含包含的IMPORTXML Xpath(Google表格)

Google Spreadsheets ImportXML / XPath-图像损坏的输出

如何使用importxml和xPath加载此“标签”

Xpath:如何使用importXML函数从Google电子表格的URL中提取值?

Xpath查询帮助Google ImportXML

importXML中的Xpath命令

谷歌表importxml xpath查询

Importxml Xpath 返回内容为空

使用 ImportXML 和 XPath 从 XML 中提取数据

importXML 中的 xpath: //comment() vs //*/comment()

如何制作正则表达式以与 xPath 和 ImportXML 一起使用?

xpath 获取 IMPORTXML 公式中 2 个标签之间的文本

使用 XPath Google 表格 importxml 函数从字典中获取单词的含义

无法在 div 中使用 importxml 和 xpath 导入文本

我无法使用 xpath 和 IMPORTXML 访问网站中的数据,因为代码片段在源数据之外

谷歌表 IMPORTXML Xpath 返回 #N/A