【发布时间】:2017-02-14 08:05:12
【问题描述】:
我正在做一个解析项目,需要我解析教育网站。这样做时,我的代码无法解析 University of Goa 站点。它没有按预期返回。 我的代码:
from bs4 import BeautifulSoup
import requests
hdrs = {'User-Agent': 'Mozilla / 5.0 (X11 Linux x86_64) AppleWebKit / 537.36 (\
KHTML, like Gecko) Chrome / 52.0.2743.116 Safari / 537.36'}
r = requests.get(url, verify=True, headers=hdrs)
result = BeautifulSoup(r.content)
print(result)
打印出来:
<html><head><script type="text/javascript">
document.location="https://www.unigoa.ac.in/result_redirect.php";
</script>
</head></html>
而不是原始的 html 解析树。我尝试将显式解析器lxml 和html5lib 传递给BeautifulSoup,但它也无法按预期工作。请帮助我。
提前致谢。
【问题讨论】:
-
那是原始解析的html树。尝试将其保存到一个 html 文件并在浏览器中打开它......(只是为了了解它的作用)
标签: python python-2.7 python-3.x parsing beautifulsoup