【发布时间】:2020-06-26 21:25:31
【问题描述】:
我正在尝试获取至尊主页的 html 来解析它。 这是我正在尝试的:
from bs4 import BeautifulSoup
all_page = requests.get('https://www.supremenewyork.com/index', headers = {
'Upgrade-Insecure-Requests': '1',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
}).text
all_page_html = BeautifulSoup(all_page,'html.parser')
print(all_page_html)
但我得到的不是 html,而是这个响应:
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"/><meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/><title>Supreme</title><meta content="Supreme. The official website of Supreme. EST 1994. NYC." name="description"/><meta content="telephone=no" name="format-detection"/><meta content="on" http-equiv="cleartype"/><meta content="notranslate" name="google"/><meta content="app-id=664573705" name="apple-itunes-app"/><link href="//www.google-analytics.com" rel="dns-prefetch"/><link href="//ssl.google-analytics.com" rel="dns-prefetch"/><link href="//d2flb1n945r21v.cloudfront.net" rel="dns-prefetch"/><script src="https://www.google.com/recaptcha/api.js">async defer</script><meta content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" id="viewport" name="viewport"/><link href="//d17ol771963kd3.cloudfront.net/assets/application-2000eb9ad53eb6df5a7d0fd8c85c0c03.css" media="all" rel="stylesheet"/><script \
e.t.c
这是一种障碍还是我错过了什么?我什至添加了请求的标头,但我仍然得到这种类型的响应而不是正常响应。
【问题讨论】:
-
上面写着
<!DOCTYPE html>和<html ...>所以我会说它是 HTML。 -
但是检查所需页面的html代码它是不同的
-
这是什么错误?
-
不是错误,我的意思是它返回另一个东西
-
如果我在网络浏览器中打开
https://www.supremenewyork.com/index并查看页面源代码,我会得到您在问题中显示的内容。
标签: python python-3.x python-requests