如何使用 selenium 定位 Instagram 关注按钮 (Python)
How to locate Instagram Follow button with selenium (Python)
我正在尝试在 Instagram 页面上找到 'follow' 按钮元素(使用 selenium)。
我找到了用户页面 (https://www.instagram.com/USERNAME/) 的主要 'follow' 按钮,代码如下:
follow_button = self.driver.find_element_by_css_selector('button')
虽然在单击上面的元素 ^ 之后,现在我正在尝试找到在您查看用户的关注者时可见的 'follow' 按钮。
Click here to see which buttons I'm referring to.
我尝试了以下代码,但它不起作用:
acc_follow_buttons = self.driver.find_elements_by_css_selector('button')
for acc in acc_follow_buttons[:15]:
acc.click()
time.sleep(1)
我也尝试过使用 Xpath 进行搜索,但没有成功。
任何有 Selenium 经验的人都可以帮助我使用代码来定位此页面上的关注按钮。
我没有 Instagram 帐户,所以我的回答有点盲目,但是关注按钮有 类 吗?如果是这样,那么您可以使用 driver.find_elements_by_class_name() 来查找特定按钮。
试试这个。此处的范围指向 followers.add 个代码,用于获取关注者计数并将其附加到 range.note 列表从 1 开始。
for i in range(1, 10):
follow = driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/ul/div/li[{}]/div/div[3]/button'.format(i))
follow.click()
time.sleep(0.5)
您必须按按钮文本搜索按钮:
Follow_Button = driver.find_element_by_xpath("//*[text()='Follow']")
我正在尝试在 Instagram 页面上找到 'follow' 按钮元素(使用 selenium)。
我找到了用户页面 (https://www.instagram.com/USERNAME/) 的主要 'follow' 按钮,代码如下:
follow_button = self.driver.find_element_by_css_selector('button')
虽然在单击上面的元素 ^ 之后,现在我正在尝试找到在您查看用户的关注者时可见的 'follow' 按钮。 Click here to see which buttons I'm referring to.
我尝试了以下代码,但它不起作用:
acc_follow_buttons = self.driver.find_elements_by_css_selector('button')
for acc in acc_follow_buttons[:15]:
acc.click()
time.sleep(1)
我也尝试过使用 Xpath 进行搜索,但没有成功。
任何有 Selenium 经验的人都可以帮助我使用代码来定位此页面上的关注按钮。
我没有 Instagram 帐户,所以我的回答有点盲目,但是关注按钮有 类 吗?如果是这样,那么您可以使用 driver.find_elements_by_class_name() 来查找特定按钮。
试试这个。此处的范围指向 followers.add 个代码,用于获取关注者计数并将其附加到 range.note 列表从 1 开始。
for i in range(1, 10):
follow = driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/ul/div/li[{}]/div/div[3]/button'.format(i))
follow.click()
time.sleep(0.5)
您必须按按钮文本搜索按钮:
Follow_Button = driver.find_element_by_xpath("//*[text()='Follow']")