1
我被困在解析部分的烂番茄网站,批评评分作为标记和单独的“%”。我遵循了一些建议,如使用find_all('span',text="true")
,但Python 3.5.1 shell返回了这个错误:AttributeError: 'NavigableString' object has no attribute 'find_all'
我也试着找到美丽的汤对象critiscore
的直接子,但收到了同样的错误。请告诉我我错了哪里。这里是我的Python代码:从美丽的汤类型'可导航字符串'和'标记'拉文本
def get_rating(address):
"""pull ratings numbers from rotten tomatoes"""
RTaddress = urllib.request.urlopen(address)
tomatoe = BeautifulSoup(RTaddress, "lxml")
for criticscore in tomatoe.find('span', class_=['meter-value superPageFontColor']):
print(''.join(criticscore.find_all('span', recursive=False))) #print the Tomatometer
而且,这里的一对烂番茄的代码我感兴趣的刮:
<div class="critic-score meter">
<a href="#contentReviews" class="unstyled articleLink" id="tomato_meter_link">
<span class="meter-tomato icon big medium-xs certified_fresh pull-left"></span>
<span class="meter-value superPageFontColor"><span>96</span>%</span>
</a>
</div>
起初我确实使用过find_all,但是python打印出了另一个与我不需要的类相同的评级。有没有办法仅使用find_all()打印第一个评分或使用find()打印评分和百分比符号? – st4rgut
谢谢,我用你的css选择器并在列表中打印第一个元素 – st4rgut