python - requests-html 未能获得预期的元素
问题描述
我是 requests-html 的新手,几天前刚刚安装。
遵循教程时:
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')
about = r.html.find('#about', first=True)
print(about.text)
教程描述的预期输出是:
About
Applications
Quotes
Getting Started
Help
Python Brochure
但实际上我得到了以下信息:
About
Applications
Quotes
Getting Started
Help
Python Brochure
Downloads
All releases
Source code
Windows
macOS
Other Platforms
License
Alternative Implementations
Documentation
.
.
.
Submit Website Bug
Status
Copyright ©2001-2021. Python Software Foundation Legal Statements Privacy Policy Powered by Heroku
window.jQuery || document.write('<script src="/static/js/libs/jquery-1.8.2.min.js"></script>') window.jQuery || document.write('<script src="/static/js/libs/jquery-ui-1.12.1.min.js"></script>')
这是从元素 <li id="about" ... 到整个 html 文档的末尾。
有人知道这个问题吗?
更新:
感谢@DarkKnight 和@CrazyChucky,
但实际上请求的 HTML 元素还没有改变:
<li id="about" class="tier-1 element-1 " aria-haspopup="true">
<a href="/about/" title="" class="">About</a>
<ul class="subnav menu" role="menu" aria-hidden="true">
<li class="tier-2 element-1" role="treeitem"><a href="/about/apps/" title="">Applications</a></li>
<li class="tier-2 element-2" role="treeitem"><a href="/about/quotes/" title="">Quotes</a></li>
<li class="tier-2 element-3" role="treeitem"><a href="/about/gettingstarted/" title="">Getting Started</a></li>
<li class="tier-2 element-4" role="treeitem"><a href="/about/help/" title="">Help</a></li>
<li class="tier-2 element-5" role="treeitem"><a href="http://brochure.getpython.info/" title="">Python Brochure</a></li>
</ul>
</li>
解决方案
推荐阅读
- gzip - Haproxy 似乎在“Accept-Encoding”标头中用 gzip 替换了 brotli
- mysql - 如何制作 node.js api 并将其部署到 heroku(postgresql 或 mySQL 数据库)
- javascript - CryptoJS 在后端解密,但不是前端
- java - 如何修复此错误消息:xhr.js:178 GET http://localhost:8080/jpa/users/undefined/accounts/undefined?
- php - 我不断收到此错误:第 8 行的语法错误,意外 ':',期待 ')'
- python - 使用“子进程调用”调用未知目录中的程序
- laravel - 基于 Laravel API 的验证/身份验证
- python - 奇怪的 GUDHI + rpy2 交互
- c - 我想在 C 中创建一个链表并对其执行某些功能。但在我的代码中找不到错误
- css - bootstrap row-cols-sm-1 不适用于卡片。应该为 1 的单元格屏幕上出现两张卡片