from bs4 import BeautifulSoup
import requests
html_text = requests.get('http://www.amazon.in/s?k=iphone&ref=nb_sb_noss_2')
print(html_text)
要获得响应200
,请使用User-Agent
HTTP头:
import requests
from bs4 import BeautifulSoup
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
}
html_text = requests.get(
"http://www.amazon.in/s?k=iphone&ref=nb_sb_noss_2", headers=headers
)
print(html_text)
打印:
<Response [200]>