简体   繁体   中英

search profiles in instagram using selenium

I'm trying to use Selenium to search a profile in an Instagram search bar. The text gets put into the search bar fine but when i hit the Enter its goes to below url which doesn't have any details.

https://www.instagram.com/explore/search/keyword/?q=python.hub

time.sleep(5)
searchbox = driver.find_element(By.CSS_SELECTOR,"input[placeholder='Search']")
searchbox.clear()
searchbox.send_keys("python.hub")
time.sleep(5)
searchbox.send_keys(Keys.ENTER)
time.sleep(5)
searchbox.send_keys(Keys.ENTER)

在此处输入图像描述

How can i choose the profile python.hub which is shown below by using the search bar itself rather than giving the profile url directly.

在此处输入图像描述

This will work fine:

driver.find_element(By.XPATH,"//*[@aria-label='Search input']").send_keys("python.hub")
time.sleep(3)
#this will click on the 1st account on the searched username.
driver.find_element(By.XPATH,'//*[@class="_abnx _aeul"]/div').click()

Or you can directly go to the page URL after login.

# after you log in to instagram
driver.get("https://www.instagram.com/python.hub/")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM