0

I tried to follow along with some youtube tutorials in order to make my code do what I want it to do, but I still haven't found any answer on the entire internet...

Here I tried to make the script using BeautifulSoup:

import bs4
import requests
resoult = requests.get("https://www.instagram.com/kyliejenner/following/")
src = resoult.content
Soup = bs4.BeautifulSoup(src, "lxml")
links = Soup.find_all("a")
print(links)
print("/n")
for link in links:
    if "FPmhX notranslate  _0imsa " in link.text:
        print(link)

And here I tried to do the same thing with Selenium, but the problem is that I don't know the next steps in order to make my code copy the usernames a user is following

import selenium
from selenium import webdriver
import time


PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://www.instagram.com/")

time.sleep(2)

username = driver.find_element_by_css_selector ("#loginForm > div > div:nth-child(1) > div > label > 
input")
username.send_keys ("my_username")

password = driver.find_element_by_css_selector ("#loginForm > div > div:nth-child(2) > div > label > 
input")
password.send_keys("password")

loginButton = driver.find_element_by_css_selector ("#loginForm > div > div:nth-child(3)")
loginButton.click()

time.sleep(3)

saveinfoButton = driver.find_element_by_css_selector ("#react-root > section > main > div > div > div 
> 
section > div > button")
saveinfoButton.click()
 
time.sleep(3)

notnowButton = driver.find_element_by_css_selector("body > div.RnEpo.Yx5HN > div > div > div > 
div.mt3GC 
> button.aOOlW.HoLwm")
notnowButton.click()

I would really appreciate it if someone could solve this problem. Again, all that I want my script to do is to copy the usernames from the "following" section of someones profile.

Dragos 9
  • 1
  • 1
  • Does this answer ur question: https://stackoverflow.com/questions/37233803/how-to-web-scrape-followers-from-instagram-web-browser – Sushil Oct 04 '20 at 03:13
  • Thank you for trying to help me but I've tried every script from that post and it didn't work, I think it's because they all use XPATH for finding elements, but in my case, only "find_element_by_css_selector" works for clicking elements on the web. – Dragos 9 Oct 04 '20 at 09:24
  • Okay...Then y don't u replace ```find_element_by_xpath``` with ```find_element_by_css_selector``` in that code? – Sushil Oct 04 '20 at 09:26

0 Answers0