首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导入how div --如何在类和id都不存在时获取信息?

导入how div --如何在类和id都不存在时获取信息?
EN

Stack Overflow用户
提问于 2018-04-05 01:59:49
回答 1查看 3.9K关注 0票数 1

在google中使用Importxml。

当信息不是div类或div id时,如何从这里获得“数据-胶片-id”和“数据-胶片-发行年”?:

代码语言:javascript
复制
<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中,使用如下:

代码语言:javascript
复制
=ImportXML(A1, "//div[contains(@class,'react-component') and contains(@class,'film-poster')]/a/@href")

所以我知道一切都正常,但那只是因为href在它自己的段落中低于这个div。我的问题是试图挖掘上面显示的信息。

在这个站点上搜索之后,我尝试了这个(包括许多其他事情),但是它导致了一个错误。

代码语言:javascript
复制
=ImportXML(A1, "//li[@class='poster-container']//div[not(@id) or not(@class)]")

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

也许我不能得到日期,因为它不是一门课或一个身份证?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-05 03:04:01

您需要使用属性选择器

代码语言:javascript
复制
=ImportXML(A1, "//div[contains(@class,'react-component') and contains(@class,'film-poster')]/attribute::data-film-id")

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

如果你想把一切都排在一排,而我不建议这样做,那就是

代码语言:javascript
复制
=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,.”中输出所有内容。很乱。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49663019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档