Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium big struggle
#1
from selenium import webdriver
from time import sleep

class scrollDown:

    def __init__(self, username, passWord):
        self.driver = webdriver.Chrome()
        self.driver.get("https://instagram.com")
        self.username = username
        self.passWord = passWord
        sleep(2)
        self.driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input")\
            .send_keys(username)
        self.driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input")\
            .send_keys(passWord)
        self.driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]/button")\
            .click()
        sleep(5)

        #REMOVE NOTIFICATIONS WINDOW
        self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div[3]/button[2]").click()
        sleep(3)
        print("Logged in")

        for i in range(100):
             self.driver.execute_script("window.scrollBy(0, 200)")
             sleep(1)
             print(str(i)+"%")

         #ALTERNATIVE
        headers = self.driver.find_elements_by_tag_name('header')
        for users in headers:
            pictureLocation = self.driver.find_element_by_class_name('O4GlU').get_attribute("href")
            stringLocation = str(pictureLocation)
            if "London" in stringLocation or "london" in stringLocation:
                nameLink = users.find_elements_by_tag_name('a')
                print(nameLink)


Basically im trying to find out who is in town from my instagram fee but im struggling with the element selection

Can anyone help me pls?
Reply
#2
Your code is much more readable if you put the Python code in a code block. Can you edit it?
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Reply
#3
from selenium import webdriver
from time import sleep
 
class scrollDown:
 
    def __init__(self, username, passWord):
        self.driver = webdriver.Chrome()
        self.driver.get("https://instagram.com")
        self.username = username
        self.passWord = passWord
        sleep(2)
        self.driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input")\
            .send_keys(username)
        self.driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input")\
            .send_keys(passWord)
        self.driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]/button")\
            .click()
        sleep(5)
 
        #REMOVE NOTIFICATIONS WINDOW
        self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div[3]/button[2]").click()
        sleep(3)
        print("Logged in")
 
        for i in range(100):
             self.driver.execute_script("window.scrollBy(0, 200)")
             sleep(1)
             print(str(i)+"%")
 
         #ALTERNATIVE
#PICK ALL THE HEADERS ==========
        headers = self.driver.find_elements_by_tag_name('header')
#LOOP THROUGH ALL OF THEM
        for users in headers:
            pictureLocation = self.driver.find_element_by_class_name('O4GlU').get_attribute("href")
            stringLocation = str(pictureLocation)
#PICK THE LOCATION ELEMENT AND CHECK IF IT MATCH "LONDON" =======
            if "London" in stringLocation or "london" in stringLocation:
                nameLink = users.find_elements_by_tag_name('a')
                print(nameLink)
I HOPE MAKES MORE SENSE NOW.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class Struggle: Connecting a Method to an Outside Variable vulpesVelox 7 4,375 Jan-27-2018, 10:11 PM
Last Post: vulpesVelox
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,587 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020