Python Selenium从照片中提取Instagram哈希标记

2024-09-29 19:19:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我在从所选照片中提取标签时遇到问题

我现在工作的代码是

<a class=" abcd" href="/explore/tags/ht1/" tabindex="0">#ht1</a>
<a class=" abcd" href="/explore/tags/ht2/" tabindex="0">#ht2</a>
<a class=" abcd" href="/explore/tags/ht3/" tabindex="0">#ht3</a>
<a class=" abcd" href="/explore/tags/ht4/" tabindex="0">#ht4</a>

所以我需要把它们放在一个列表上,所以我写

tags = driver.find_elements_by_class_name('abcd')

这样就行了,我可以打印列表并检查Ht的确切数量

但当我这么做的时候

tags[0].text

只执行一条白线,我需要打印“#ht1” 我用其他单一类测试了这一点,结果成功了,我认为问题在于打印列表


Tags: 代码列表drivertags标签explore照片class
1条回答
网友
1楼 · 发布于 2024-09-29 19:19:18

您可能需要等待页面加载和元素变得可见

tags = driver.find_elements_by_class_name('abcd')

取代

WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CLASS_NAME,"abcd")))

进口

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

相关问题 更多 >

    热门问题