我会先说我对Python有点新鲜。我最近在Slack机器人上工作,这里是我目前所处的位置。在BS4中使用findAll创建列表
source = requests.get(url).content
soup = BeautifulSoup(source, 'html.parser')
price = soup.findAll("a", {"class":"pricing"})["quantity"]
这是我试图抓取的HTML代码。
<a class="pricing" saleprice="240.00" quantity="1" added="2017-01-01"> S </a>
<a class="pricing" saleprice="21.00" quantity="5" added="2017-03-14"> M </a>
<a class="pricing" saleprice="139.00" quantity="19" added="2017-06-21"> L </a>
当我只用soup.find()
,我能找到的第一个量值,但我需要一个列表中所有的人。我考虑使用不同的库,如lxml而不是bs4,但没有任何运气。任何帮助真的很感激,因为我已经花了很长时间在这个。
只需注意''.findAll'确实只是为了向后兼容,我相信在leui中不推荐使用更多的Python-y命名约定。我建议使用'.find_all'移动foward。 –