我正在開發一個自動 Instagram 追隨者機器人。這是 Udemy 上 100 天代碼的練習。
我的元素有問題。我找不到追隨者標簽。
來自 Instagram 的個人資料
我使用以下代碼:
def find_follower(self):
time.sleep(2)
self.driver.get(f"https://www.instagram.com/{SIMILAR_ACCOUNT}")
time.sleep(2)
path = self.driver.find_element(by=By.CLASS_NAME, value="_aa_c")
print(path.text)
this_is_what_I_want = self.driver.find_elements(by=By.XPATH, value="//a[@href]")
for item in next2:
element = item.find_element(by=By.TAG_NAME, value="span").get_attribute("_ac2a _ac2b").click()
我想推送關注者鏈接。我知道代碼是錯誤的。我嘗試了很多標簽,但沒有任何效果。
有人有什么想法嗎?非常感謝
此致
萊文
uj5u.com熱心網友回復:
要單擊“關注者”按鈕,請嘗試以下操作:
self.driver.find_elements(By.CSS_SELECTOR, "a[href*='followers']").click()
或者,如果您更喜歡 XPath
self.driver.find_elements(By.XPATH, "//a[contains(@href,'followers')]").click()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/518194.html
上一篇:使用rvest抓取圖片
