【发布时间】:2020-04-04 06:16:35
【问题描述】:
当您在 Instagram 网站上点击用户的用户名时,我正在尝试自动点击 Instagram 关注按钮。
点击用户名后,点击关注者,会打开一个窗口,其中包含关注此人的人,并且有关注按钮
这是新窗口的截图
我正在尝试通过 python selenium 一个一个地单击按钮,但我尝试的任何操作似乎都不起作用。
我得到的最好的结果是一个 for 循环,它使用 xpath 只点击了第一个跟随按钮,但没有点击其他按钮。
#click the followers button to dispaly the users followers
driver.find_element_by_partial_link_text("followers").click()
time.sleep(3)
#scroll through the followers list to a specified heeight
scroll_box=driver.find_element_by_xpath("/html/body/div[4]/div/div[2]")
last_ht, ht=0, 1
while last_ht !=ht:
last_ht=ht
time.sleep(2)
ht=driver.execute_script("""arguments[0].scrollTo(0, 2000);
return 2000;
""", scroll_box)
#follow users up to the specified height
follow=driver.find_elements_by_xpath("/html/body/div[4]/div/div[2]/ul/div/li[1]/div/div[3]/button")
for x in range (0,len(follow)):
follow[x].click()
time.sleep(2)
time.sleep(1)
【问题讨论】:
标签: python selenium automation instagram