BeautifulSoup 对象方法
来源:互联网 发布:王者归来 软件程序 编辑:程序博客网 时间:2024/06/15 06:50
from bs4 import BeautifulSoup,Tag,CDataimport redoc = ['<html><head><title>Page title</title></head>', '<body><p id="firstpara" align="center">This is paragraph <b>one</b>.</p>', '<p id="secondpara" align="blah">This is paragraph <b>two</b>.</p>', '</body></html>']soup = BeautifulSoup(''.join(doc))print(soup.prettify)print(soup.contents[0].name)print(soup.contents[0].contents[0].name)print(soup.contents[0].contents[0].contents[0].string)head = soup.contents[0].contents[0]print(head.parent.name)print(head.next)print(head.nextSibling.name)print(head.nextSibling.contents[0])print(head.nextSibling.contents[0]) print(soup.findAll('p', align="center"))print(soup.find('p', align="center"))print(soup('p', align ="center")[0]['id'])print(soup.find('p').b.string)print(soup('p')[1].b.string)titleTag = soup.html.head.titletitleTag['id'] = 'theTitle'print(titleTag)titleTag.contents[0].replaceWith("new title")soup.p.replaceWith(soup.b)print(soup.prettify)soup.body.insert(0, "this page used to have")
0 0
- BeautifulSoup 对象方法
- BeautifulSoup常用方法
- BeautifulSoup库入门级方法
- BeautifulSoup库中find_all()方法
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- beautifulsoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- beautifulsoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- BeautifulSoup
- 使用share SDK实现腾讯微博授权登录分享(1.x版本)
- 移动广告+太空升降机
- Linux编辑器vi使用方法
- 进程/线程同步互斥与通信及socket传输
- ASP.NET Ajax学习笔记(二)客户端调用WebService
- BeautifulSoup 对象方法
- mysql —— 分表分区
- 第6周作业2-IF语句大显身手之成绩判断
- Codeforces Round #233 (Div. 2)
- 「教程」破解Splashtop Xdisplay并将iPad变成PC的扩展显示器
- 项目的生命周期
- 文件系统错误修复实例(1)
- 核实到基督教搜
- 八叛逆