Python 使用selenium库创建Instagram Bot
所以我尝试创建insta机器人,它在搜索栏中打开一个特定的标签,然后导航到它。我一直有一个问题,导航机器人到搜索栏,它总是告诉我,路径是无法找到的,有什么想法,我如何使机器人目标搜索栏和发送标签键给它?这是我的密码:Python 使用selenium库创建Instagram Bot,python,python-3.x,selenium,instagram,bots,Python,Python 3.x,Selenium,Instagram,Bots,所以我尝试创建insta机器人,它在搜索栏中打开一个特定的标签,然后导航到它。我一直有一个问题,导航机器人到搜索栏,它总是告诉我,路径是无法找到的,有什么想法,我如何使机器人目标搜索栏和发送标签键给它?这是我的密码: from selenium import webdriver from time import sleep from insta import username,password,hashtag class InstaBot(): def __init__(self):
from selenium import webdriver
from time import sleep
from insta import username,password,hashtag
class InstaBot():
def __init__(self):
self.driver = webdriver.Chrome()
def login(self):
self.driver.get('https://www.instagram.com/')
sleep(3)
#loggin in to instagram with facebook
fb_btn = self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[1]/button')
fb_btn.click()
#logging into acc
email = self.driver.find_element_by_xpath('//*[@id="email"]')
email.send_keys(username)
pswd = self.driver.find_element_by_xpath('//*[@id="pass"]')
pswd.send_keys(password)
login_btn = self.driver.find_element_by_xpath('//*[@id="loginbutton"]')
login_btn.click()
sleep(4)
self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
.click()
#navigating to search bar and sending hashtag into it
hashtag = self.driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[1]/a/svg')
hashtag.send_keys(hashtag)
您可以通过执行JavaScript导航到搜索栏:
SCRIPT=f“document.getElementsByClassName('XTCLo x3qfX')[0]。值=“{SEARCH_value}”
驱动程序。执行_脚本(脚本)
但是,如果您只想转到hashtag页面,我建议您使用
driver.get(f)https://www.instagram.com/explore/tags/{HASHTAG}/”
您可以直接发送页面,例如:
https://www.instagram.com/explore/tags/{hastags}/
所以
当你运行这个程序时,有时它可以点击不同的按钮,为什么当它制作同一个程序时它会这样做:)当你直接发送hastags的lınk时,它会去那里,甚至程序点击不同的按钮insta是分开的.py文件,我有我的用户信息尝试使用
/input[@placeholder='Search']
xpath.it工作正常,但到目前为止,它没有将键发送到搜索栏中,因为TypeError:type'WebElement'的对象没有len()