所以我想单击红色矩形中的元素来浏览所有关注者,但我无法让它单击它。这是我尝试过的,但没有成功:
1#driver.find_elements_by_partial_link_text('abonniert').click()
2#driver.find_elements_by_xpath('//*[@id="react-root"]/section/main/div/header/section/ul/li[3]/a').click()
3#driver.find_elements_by_xpath('//*[@id="react-root"]/section/main/div/header/section/ul/li[3]/a').click()
这就是我的“驱动程序”的定义方式。
driver = webdriver.Chrome(executable_path=r"C:/bin/chromedriver")
我无法让它工作,所以我真的很愿意寻求帮助
最佳答案
您的第一次尝试几乎是正确的,您只需访问 find_elements_by_partial_link_text
返回的列表的第一个元素,如下所示:
driver.find_elements_by_partial_link_text('abonniert')[0].click()
但是,单击 Instagram 中的以下选项卡需要您登录,因此此处可能需要执行其他步骤。
关于python - 获取可点击列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59382448/