简体   繁体   English

Beautiful Soup 结果中缺少部分

[英]Missing parts in Beautiful Soup results

I'm trying to retrieve the table in the ul tag in the following html code, which mostly looks like this:我正在尝试在以下 html 代码中检索 ul 标记中的表,该代码主要如下所示:

 <ul class='list' id='js_list'> <li class="first"> <div class="meta"> <div class="avatar">...</div> <div class="name">黑崎一护</div> <div class="type">...</div> </div> <div class="rates"> <div class="winrate">56.11%</div> <div class="pickrate">7.44%</div> </div> </li> </ul>

but just with more entries.但只是有更多的条目。 It's from this website.它来自这个网站。

So far I have this (for specifically getting the win rates):到目前为止,我有这个(专门用于获得获胜率):

 from bs4 import BeautifulSoup import requests r = requests.get("https://moba.163.com/m/wx/ss/") soup = BeautifulSoup(r.content, 'html5lib') win_rates = soup.find_all('div', class_ = "winrate")

But this returns empty and it seems like the farthest Beautiful Soup was able to get was the ul tag, but none of the information under it.但这返回为空,似乎 Beautiful Soup 能够获得的最远的是 ul 标签,但它下面没有任何信息。 Is this a parsing issue?这是解析问题吗? Or is there JavaScript source code that I'm missing?还是我缺少 JavaScript 源代码?

I think your issue is that your format is incorrect for pulling the div with the attribute.我认为您的问题是您的格式对于使用属性拉动 div 是不正确的。 I was able to pull the winrate div with this:我可以用这个来拉取胜率 div:

soup.find('div',attrs={'class':'winrate'})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM