#🔒 Selenium / webscrapping

35 messages · Page 1 of 1 (latest)

agile lichen
#

Hello, so im trying to get the last messages sent from the chat, but i can only have the first one, tried many things to get the others but i can't, can someone help me please ? Thanks Pinkheart

lyric thistleBOT
#

@agile lichen

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

agile lichen
glacial torrent
#

Try find_elements instead of find_element

#

I didn’t really look at your code that’s just my guess based on what you said @agile lichen

agile lichen
glacial torrent
#

Find elements gives a list

agile lichen
glacial torrent
#

So you have to loop through the list to print each out

#

Do you get what I mean

agile lichen
#

<selenium.webdriver.remote.webelement.WebElement (session="28a72d706d8a49c101abce32c651cfae", element="f.2ACF44E19131897FFF63F4394EC88B05.d.89C5AE03BD68D29B0CD9422E261D70A2.e.110")>

#

got this

glacial torrent
#

Show me your code now

agile lichen
#

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time
import os
from dotenv import load_dotenv
from typing import Final
load_dotenv
USER : Final[str] = os.getenv('user')
PASSWORD : Final[str] = os.getenv('password')
os.system("cls")

[[ -- Truc chiant pour selenium -- ]]

class Browser:
def init(self, driver_path):
self.driver_path = driver_path

    chrome_options = Options()
    chrome_options.add_argument("--disable-search-engine-choice-screen")
    WINDOW_SIZE = "1000,800"
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
    chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
    chrome_options.add_experimental_option("detach", True)
    chrome_options.add_argument("--incognito")
    service = Service(self.driver_path)
    
    self.browser = webdriver.Chrome(service=service, options=chrome_options)

def open_page(self, url: str):
    self.browser.get(url)

def close_browser(self):
    self.browser.quit()

def add_input(self, by: By, locator: str, text: str):
    field = self.browser.find_element(by, locator)
    field.send_keys(text)
    time.sleep(1)

def click_button(self, by: By, locator: str):
    button = self.browser.find_element(by, locator)
    button.click()
    time.sleep(1)

def login(self, username: str, password: str):
    usern_intput = self.add_input(By.NAME, 'login', username)
    pass_input = self.add_input(By.NAME, 'password', password)
    self.click_button(By.XPATH,"/html/body/div[1]/div/div[2]/div[1]/div/div/div[4]/div[2]/div/div/form/div[1]/dl/dd/div/div[2]/button")

Findings texts in the div

def cherche_com(self):
    path = self.browser.find_elements(By.CLASS_NAME,'siropuChatMessageContentLeft')
    print(path[0])

if name == 'main':
driver_path = r"D:\CODE\checker wearline\chromedriver.exe"
browser = Browser(driver_path)
browser.open_page("https://gtacityrp.fr/index.php?login/")
time.sleep(2)
browser.login(USER,PASSWORD)
browser.cherche_com()
time.sleep(10)
browser.close_browser()

lyric thistleBOT
#

Hey @agile lichen!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
glacial torrent
#

Path[0].text

#

Try that

#

You probably want path[-1].text tbh

agile lichen
#

damn

#

seems like it's working

#

nvm

#

still givin the first

glacial torrent
#

Did you put 0

#

Or -1

agile lichen
#

ight it's working nvm

#

thanks

#

for your help !

glacial torrent
#

Find element only gives the first element it finds

#

So if you need to get all the elements you’ll need find elements

#

Np

agile lichen
#

thanks !

#

!close

lyric thistleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.