我尝试向网站发送请求,但在运行我的代码后,它会永远运行并且没有任何响应。请有人帮助我
import requests
req = requests.session()
url = "https://www.stepstone.de/"
response = req.get(url)
print(response.status_code)
我尝试在其中添加一些标题,但它对我不起作用,如果您有任何建议,我将不胜感激与我分享
通过设置
User-Agent
标头,我能够从服务器获取响应:
import requests
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0"
}
url = "https://www.stepstone.de/"
html_text = requests.get(url, headers=headers).text
print(html_text)
打印:
<!DOCTYPE html>
<html lang="de">
<head>
<title>Jobs sind unser Job | Stepstone</title>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://www.stepstone.de",
"logo": "https://www.stepstone.de/sharedassets/logo/core/stepstone/logo.svg"
}
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
...