Scraping Dynamic JavaScript Websites
First try: inspect network calls
Section titled “First try: inspect network calls”Many “dynamic” sites load data from JSON endpoints.
Use browser devtools Network tab and try:
- call the JSON endpoint with
requests - avoid full browser automation
Selenium approach
Section titled “Selenium approach”- open page
- wait for element
- extract HTML
from selenium import webdriver
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
html = driver.page_source
print(html[:500])
finally:
driver.quit()- more fragile
- slower
- easier to get blocked
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading