1

I'm trying to crawl this website, problem is it's dynamically loaded.

Basically I want what I can see from the browser console, not what I see when I right click > show sources.

I've tried some selenium examples but I can't get what I need. The code below uses selenium and get only what you get in right click -> show code. How can I get the content of the loaded page?

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

# Start the WebDriver and load the page
wd = webdriver.Firefox()
wd.get("https://www.leforem.be/particuliers/offres-emploi-recherche-par-criteres.html?exParfullText=&exPar_search_=true&    exParGeographyEdi=true")

# Wait for the dynamically loaded elements to show up
time.sleep(5)

# And grab the page HTML source
html_page = wd.page_source
wd.quit()

# Now you can use html_page as you like

print(html_page)

1 Answer 1

2

You need to explicitly wait for the search results to appear before getting the page source:

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


wd = webdriver.Firefox()
wd.get("https://www.leforem.be/particuliers/offres-emploi-recherche-par-criteres.html?exParfullText=&exPar_search_=true&    exParGeographyEdi=true")

wd.switch_to.frame("cible")

wait = WebDriverWait(wd, 10)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'td.resultatIntitule')))

print(wd.page_source)
Sign up to request clarification or add additional context in comments.

2 Comments

Thx I didn't know that. However it's hanging now and I get an error like selenium.common.exceptions.TimeoutException: Message: Stacktrace: at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpnfzF0g/extensions/[email protected]/components/driver-component.js:10299) So I guess it didn't find it.. But I see it in the elements
@dkx22 thanks for trying it out. There is an iframe that you need to switch to - updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.