简体   繁体   中英

scraping with request with bs4

I am try to scrape this page getting a 406 error. what am i doing wrong please?

import requests
from bs4 import BeautifulSoup

url="http://chucknorrisfacts.net/facts"

response = request.get(url)
print(response)

add the headers parameter:

import requests
from bs4 import BeautifulSoup

url="http://chucknorrisfacts.net/facts"
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'}

response = requests.get(url,headers=headers)
print(response)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM