Scraper in Python gives “Access Denied”

前端 未结 3 1276
青春惊慌失措
青春惊慌失措 2020-12-19 12:35

I\'m trying to code a scraper in Python to get some info from a page. Like the title of the offers that appear on this page:
https://www.justdial.com/Panipat/Saree-Retai

3条回答
  •  一整个雨季
    2020-12-19 12:42

    As was mentioned in comments, you need to specify allowable user-agent and pass it as headers:

    def extract_source(url):
        headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0'}
        source=requests.get(url, headers=headers).text
        return source
    

提交回复
热议问题