Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I recently started with coding, I use Python and Pycharm. I Installed and imported the needed "Add-ons" like Selenium.
For my first project I tried to get the "address" information from this website:

https://randomstreetview.com/#fullscreen

When I use the Chrome developer tools (F12) the information shows up after the div'address'. After lots of trial and error I managed to scrape the website in multiple ways but nothing ever showed up behind the div.
Due to that I looked it up and think it's a dynamic information, so I started trying to use Selenium and other code that I found online.
Nothing worked or I didn't manage to get it working.
The address changes everytime when you open the website but the place stays the same (afaik).
Can anyone help me with a working code or help me to get on the right way?
I could provide my different approaches but I won't think that would help. See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you want the element's address just get the element and print it's text.

driver.get("https://randomstreetview.com/")
wait = WebDriverWait(driver, 10)
elem = wait.until(EC.presence_of_element_located((By.ID, "address")))
print(elem.text)

Element

<div id="address">Nordre Ringvej 97, 2600 Glostrup, D?nemark</div>

Outputs

Nordre Ringvej 97, 2600 Glostrup, D?nemark

Imports

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...