【发布时间】:2020-02-03 06:12:26
【问题描述】:
所以我正在尝试创建在搜索栏中打开特定主题标签然后导航到它的 insta 机器人。我在将机器人导航到搜索栏时遇到问题,它总是告诉我找不到路径,有什么想法可以让机器人目标搜索栏并向其发送主题标签键吗?这是我的代码:
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)
【问题讨论】:
-
insta 是分开的 .py 文件,我有我的用户信息
-
尝试使用
//input[@placeholder='Search']xpath。 -
它有效,但目前它没有将键发送到搜索栏中给出 TypeError: object of type 'WebElement' has no len()
标签: python python-3.x selenium instagram bots