Skip to content

Instantly share code, notes, and snippets.

@alexfazio
Created January 4, 2025 08:48
Show Gist options
  • Select an option

  • Save alexfazio/3c80db32c21ca335cbf4ca57cf07123b to your computer and use it in GitHub Desktop.

Select an option

Save alexfazio/3c80db32c21ca335cbf4ca57cf07123b to your computer and use it in GitHub Desktop.
Follow Redirect Without Headless Mode
import time
import undetected_chromedriver as uc
def analyze_redirect_with_undetected_chromedriver_stealth(url):
"""
Uses 'undetected_chromedriver' in non-headless mode for a stealthier approach,
helping bypass basic detection and possible Cloudflare checks.
"""
print("=== Using undetected-chromedriver (non-headless) ===")
print(f"Navigating to: {url}\n")
options = uc.ChromeOptions()
# Stealth flags
options.add_argument("--disable-blink-features=AutomationControlled")
# Custom User-Agent to appear more like a real browser
options.add_argument(
"user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/110.0.5481.77 Safari/537.36"
)
driver = uc.Chrome(options=options)
try:
driver.get(url)
# Allow time for potential JavaScript redirects or anti-bot checks
time.sleep(5)
final_url = driver.current_url
print("Final URL (according to undetected-chromedriver):", final_url)
finally:
driver.quit()
if __name__ == "__main__":
test_url = (
"https://www.cardmarket.com/en/Pokemon/Products/"
"Search?searchString=Ghetsis+%28PLF+115%29&referrer=pkmncards"
"&utm_source=pkmncards&utm_medium=single+30878+&utm_campaign=affiliate&mode=gallery"
)
analyze_redirect_with_undetected_chromedriver_stealth(test_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment