python - 使用 Python 和 selenium 从 Tweet 中提取 YouTube 链接

标签 python selenium twitter youtube bots

我正在尝试从特定推文中钓鱼 YouTube 链接并在浏览器中打开它。

我打开 Tweet 的 URL(https://twitter.com/MrSlagovich/status/1189669505829670912),然后尝试从中获取 YouTube 链接。这是哪个 (https://youtu.be/le2v90CQyhs)

我尝试使用按名称查找元素按标签查找元素,但我似乎无法将网址从页面中取出。任何帮助都会很棒。以下是我当前的绑定(bind)代码。
YTLink = bot.find_element_by_tag_name("iframe").get_attribute("src")

最佳答案

试试这个:

url = 'https://twitter.com/MrSlagovich/status/1189669505829670912'

driver = webdriver.Chrome()
driver.get(url)

overlay=driver.find_element_by_id("permalink-overlay-dialog")
YTLink=overlay.find_element_by_xpath("//a[@class='twitter-timeline-link u-hidden']").get_attribute("title")

关于python - 使用 Python 和 selenium 从 Tweet 中提取 YouTube 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58647481/

相关文章:

python - 比较两个字符串并返回最相似的一个

python - InvalidArgumentException:消息:无效参数:用户数据目录已在使用错误使用 --user-data-dir 使用 Selenium 启动 Chrome

iphone - 与许多服务提供商合作的 Obj-c 的 OAuth 消费者库

javascript - 推文按钮在 IE7 中无法正确显示,但在 mozilla、chrome 和 IE 8 中工作正常

python - 解析存储在 pandas 数据框列中的推文

python - 在 Matplotlib 中创建箱线图均值线和中值线的键

python - 如何基于 SQLAlchemy 中关联对象中的条目值进行约束?

python - 从检测颜色python opencv中获取值

python - 使用 Python 和 Selenium 单击

django - 在 Django 中加载用于 Selenium 测试的装置时出现完整性错误