美丽的汤 - html 解析器返回点而不是网络上可见的字符串
我正在尝试从以下位置获取演员数量: https://apify.com/store以下 HTML:
<div class="ActorStore-statusNbHits">
<span class="ActorStore-statusNbHitsNumber">895</span>results</div>
当我发送 get
请求并使用 BeautifulSoup
解析响应时:
r = requests.get(base_url)
soup = BeautifulSoup(r.text, "html.parser")
return soup.find("span", class_="ActorStore-statusNbHitsNumber").text
我得到三个点 ...
而不是数字 895
元素是 ...
如何获取号码?
I'm trying to get the number of actors from: https://apify.com/store which is under the following HTML:
<div class="ActorStore-statusNbHits">
<span class="ActorStore-statusNbHitsNumber">895</span>results</div>
When I send get
request and parse response with BeautifulSoup
using:
r = requests.get(base_url)
soup = BeautifulSoup(r.text, "html.parser")
return soup.find("span", class_="ActorStore-statusNbHitsNumber").text
I get three dots ...
instead of the number 895
the element is <span class="ActorStore-statusNbHitsNumber">...</span>
How can I get the number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在浏览器中检查网络调用(按 F12)并按
XHR
进行过滤,您将看到数据是通过以下方式动态加载的:发送POST
请求:您可以通过发送正确的
json
数据来模拟该请求。不需要BeautifulSoup
,您只需使用requests
模块。这是一个完整的工作示例:
输出:
要查看所有 JSON 数据以访问键/值对,您可以使用:
部分输出:
If you inspect the network calls in your browser (press F12) and filter by
XHR
, you'll see that the data is loaded dynamically via sending aPOST
request:You can mimic that request via sending the correct
json
data. There's no need forBeautifulSoup
you can use only therequests
module.Here is a complete working example:
Output:
To view all the JSON data in order to access the key/value pairs, you can use:
Partial output: