python - Python BeautifulSoup - 查找特定的
问题描述
我尝试从以下 HTML 中提取“li”:
我试过这样:
soup = BeautifulSoup(html, 'html.parser')
containers = soup.find('div', {'class': 'pagination-container'}).find('ul')`
containers.li
但我没有得到预期的结果。谁能帮我?
解决方案
soup.find_all('li')[0]
用于搜索页面上的所有 li,0 用于索引它。
soup.find_all('span', class_='ad')
搜索带有类广告的跨度
我的跨度包含很多其他跨度的数据,我想摆脱这些数据,我知道我正在寻找这个特定的词
Artist = soup.find_all('h1')[0]
Artist = re.search('<h1>(.*)<span', str(Artist))
Artist = Artist.group(0)
Artist = str(Artist).replace('<h1>','')
Artist = str(Artist).replace('<span','')
我没有想出更好的东西,但它奏效了..我也很乐意推荐:)
推荐阅读
- arm-none-eabi-gcc - arm-none-eabi-gcc 代码程序如何在 x86 机器上运行?
- kubernetes - 使用 toYaml 进行 helm 模板化
- python - 当我尝试对 gpiozero 变量进行舍入时出现错误
- mqtt - 蚊子桥发布导致 OOM 崩溃
- swift - 首次发射后如何终止 Swift Combine 响应?
- mysql - 找出sql查询的不同之处
- visual-studio - SSIS优先约束的设计接口
- r - 如何在 R 中获得与 Stata 中相同的 AIC 和 BIC 值?
- java - 如何在 MySQL 中导致死锁
- reactjs - 社交媒体登录后如何动态重定向到私有路由?