猿问

使用漂亮的汤在无序列表中选择单个项目

我正在尝试通过美丽的汤解析的项目列表进行排序。每个项目都有唯一的链接和文本,但是除了列表中的第一个项目外,我不知道如何选择单个项目。


#Finds all div's with class image_list

containers = page_soup.findAll("div", {"class": "image_list"})


#selects the ul with the links I want to sort through

RHAZ = containers[1]

这是我没有运气尝试过的一些方法:


#200 is one of the unique numbers a li has.

RHAZ.li.findAll("a", {"href":"200"})


RHAZ.li.findAll("a", {"text":"200"})

这就是页面中HTML的外观


<div class="image_list">

 <ul>

   <li><a href="./?s=2127&camera=RHAZ%5F">Sol 2127 (4 img)</a></li>

   <li><a href="./?s=2126&camera=RHAZ%5F">Sol 2126 (4 img)</a></li>

    ....

从2127-1开始。


蝴蝶刀刀
浏览 112回答 3
3回答
随时随地看视频慕课网APP

相关分类

Python
我要回答