在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] 删除。
我来说两句