请使用返回响应代码503的请求模块清除我对该python代码的查询


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-AgentHTTP头:

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]>

最新更新