gpt4 book ai didi

Meta Open Graph xpath 选择器的 Python Selenium 问题

转载 作者:太空宇宙 更新时间:2023-11-04 04:24:36 25 4
gpt4 key购买 nike

我已经确认 xpath 使用测试 xpath 的 Google Chrome 插件工作。这是 xpath:

//元[@property='og:url']/@content

这是与其他 xpath 一起工作的代码行,所以我知道唯一的变量是当前的 xpath:

pageID = get_data(driver,"//meta[@property='og:url']/@content")

但是当我运行 Python Selenium 脚本时出现错误:

“无效的选择器”“它应该是一个元素。”

我只能使用可见的 xpath 吗?如何选择需要查看页面源的隐藏元素?

注意:谢谢您,如果我遗漏了任何信息,我深表歉意。这是我在这里的第一篇文章,我只创建了一个配置文件,因为我在网上到处搜索都找不到解决方案。

最佳答案

从问题中不清楚方法get_data()是如何定义的。

但是,要提取 pageID,您可以使用 find_element_by_xpath()get_attribute()方法如下:

pageID = driver.find_element_by_xpath("//meta[@property='og:url']").get_attribute("content")

关于Meta Open Graph xpath 选择器的 Python Selenium 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53737631/

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