I am leaving an inquiry because I couldn't click on Selenium Instagram Crawling's first post.

Asked 2 years ago, Updated 2 years ago, 52 views

Hello! I've looked it up as much as I can, but it's really weird, so I'm asking!

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import time as time



mobile_emulation = { "deviceName": "Nexus 5" }
chrome_options = Options()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome('Chromedriver.exe', chrome_options = chrome_options)


url = 'https://www.instagram.com/'
driver.get(url)





time.sleep(3)


driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div/div/div/div[3]/button[1]').click()


time.sleep(3)



driver.find_element_by_xpath('//*[@id="loginForm"]/div[1]/div[3]/div/label/input').send_keys ('ID')
driver.find_element_by_xpath('//*[@id="loginForm"]/div[1]/div[4]/div/label/input').send_keys ('password')
driver.find_element_by_xpath('//*[@id="loginForm"]/div[1]/div[6]').click()



time.sleep(3)

driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div/div/button').click()


time.sleep(3)
driver.get('https://www.instagram.com/imvely_jihyun/')



time.sleep(3)




driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[3]/article/div/div/div/div[1]/a/div/div[2]').click() 

The full code is as above. Accessed Chrome mobile mode to get comments. The problem is that I'm trying to click on the first post at the end, but it's not working anymore. The search button and the rest of the parts are clicked well Unfortunately, only the first post is not being clicked.

python selenium crawling

2022-09-20 16:20

1 Answers

Maybe you specified the wrong object?

I think you should click the following object.

#driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[3]/article/div/div/div/div[1]/a/div/div[2]').click()
# To select a selector rather than an x-pass
driver.find_element_by_css_selector('#react-root > section > main > div > div._2z6nI > article > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(1) > a > div.eLAPa > div._9AhH0').click()


2022-09-20 16:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.