[Python] How to avoid a bot detection and scrape a website using python?

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024.

  1. Stack

    Stack Membro Participativo

    I want to scrape the following website: https://www.coches.net/segunda-mano/.

    But every time I open it with python selenium, I get the message that they detected me as a bot.

    How can I bypass this detection?

    First I tried simple code with selenium:

    from selenium import webdriver
    from bs4 import BeautifulSoup

    browser = webdriver.Chrome('C:/Python38/chromedriver.exe')
    URL = 'https://www.coches.net/segunda-mano/'
    browser.get(URL)


    Then I tried it with request, but it doesn't work, too.

    from selenium import webdriver
    from bs4 import BeautifulSoup

    from fake_useragent import UserAgent

    import requests

    ua = UserAgent()

    headers = {"UserAgent":ua.random}

    URL = 'https://www.coches.net/segunda-mano/'
    r = requests.get(URL, headers = headers)

    print(r.statuscode)


    In this case I get the message 403 = Status code stating that access to the URL is prohibited.

    Don't know how to get entry to this webpage without getting blocked. I would be very grateful for your help.

    Continue reading...

Compartilhe esta Página