所以我想为自己做一个小型的instagram机器人。我会手动打开一些不同的instagram用户的标签页(因为我的机器人无法执行此操作),然后搜索“ sc”或“ snapchat”以及之后的内容。然后我想保存它,然后用'send.keys(Keys.Control + Keys.Tab)更改选项卡,然后再次搜索。但是我能找到的所有信息以及如何登录的方法。您能否在现有选项卡中运行python程序,然后搜索一些字符串。我最了解的知识是C ++,因为我们是在学校学习的。
driver = webdriver.Chrome(executable_path=r"C:/bin/chromedriver")
driver.implicitly_wait(2)
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
driver.find_element_by_name('username').send_keys(username)
driver.find_element_by_name('password').send_keys(password)
#This is just for the login,getting to the website and finding the username
#and password field to fillout.
这将用于登录,单击按钮并进入主屏幕
#Here i couldn´t find a method to click the button so i used the key tab to get
#on the button and then click it
driver.find_element_by_name("password").send_keys(u'\ue007')
ui.WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,".aOOlW.HoLwm"))).click()
driver.implicitly_wait(2)
driver.find_element_by_css_selector("body").click()
#at the end i would click an automated instagram popup away
#here i would go to the searchbar and type in the wanted user
instagram = 'userxy'
driver.find_element_by_css_selector("#react-root > section > nav > div._8MQSO.Cx7Bp > div > div > div.LWmhU._0aCwM > input").send_keys(instagram)
driver.implicitly_wait(15)
我找不到有效的方法或我无法理解的方法,但是如果instagram用户的个人简历名称中包含snapchat的名字,则会将其保存到文件中。例如,我将输入“ the rock”,如果他的传记中有“ snapchat:therock”这样的字眼,它将保存整个字符串