beautifulSoup(1)
import re
from bs4 import BeautifulSoup
doc = ['<html><head><title>Page title</title></head>',
'<body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
'<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
'</html>']
soup = BeautifulSoup(''.join(doc))
print(soup.prettify())
title=soup.html.head.title
print(title)
print(title.string)
print(len(soup('p')))
print(soup.findAll('p',align='center'))
print(soup.find('p',align='center'))
print(soup('p',align='center')[0]['id'])
print(soup.find('p',align=re.compile('^b.*'))['id'])
print(soup.find('p').b.string)
print(soup('p')[1].b.string)
-----------------------------------------------------------------------------------
<html>
<head>
<title>
Page title
</title>
</head>
<body>
<p align="center" id="firstpara">
This is paragraph
<b>
one
</b>
.
<p align="blah" id="secondpara">
This is paragraph
<b>
two
</b>
.
</p>
</p>
</body>
</html>
<title>Page title</title>
Page title
2
[<p align="center" id="firstpara">This is paragraph <b>one</b>.<p align="blah" id="secondpara">This is paragraph <b>two</b>.</p></p>]
<p align="center" id="firstpara">This is paragraph <b>one</b>.<p align="blah" id="secondpara">This is paragraph <b>two</b>.</p></p>
firstpara
secondpara
one
two
[Finished in 0.5s]
beautifulSoup(1)的更多相关文章
- Python爬虫小白入门(三)BeautifulSoup库
# 一.前言 *** 上一篇演示了如何使用requests模块向网站发送http请求,获取到网页的HTML数据.这篇来演示如何使用BeautifulSoup模块来从HTML文本中提取我们想要的数据. ...
- 使用beautifulsoup与requests爬取数据
1.安装需要的库 bs4 beautifulSoup requests lxml如果使用mongodb存取数据,安装一下pymongo插件 2.常见问题 1> lxml安装问题 如果遇到lxm ...
- BeautifulSoup :功能使用
# -*- coding: utf-8 -*- ''' # Author : Solomon Xie # Usage : 测试BeautifulSoup一些用法及容易出bug的地方 # Envirom ...
- BeautifulSoup研究一
BeautifulSoup的文档见 https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ 其中.contents 会将换行也记录为一个子节 ...
- BeautifulSoup
参考:http://www.freebuf.com/news/special/96763.html 相关资料:http://www.jb51.net/article/65287.htm 1.Pytho ...
- BeautifulSoup Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.
BeautifulSoup很赞的东西 最近出现一个问题:Python 3.3 soup=BeautifulSoup(urllib.request.urlopen(url_path),"htm ...
- python BeautifulSoup模块的简要介绍
常用介绍: pip install beautifulsoup4 # 安装模块 from bs4 import BeautifulSoup # 导入模块 soup = BeautifulSoup(ht ...
- BeautifulSoup 的用法
转自:http://cuiqingcai.com/1319.html Beautiful Soup支持Python标准库中的HTML解析器,还支持一些第三方的解析器,如果我们不安装它,则 Python ...
- BeautifulSoup的选择器
用BeautifulSoup查找指定标签(元素)的时候,有几种方法: soup=BeautifulSoup(html) 1.soup.find_all(tagName),返回一个指定Tag元素的列表 ...
随机推荐
- co.js - 让异步代码同步化
近期在全力开发个人网站,并且又沉淀了一些前后端的技术.近期会频繁更新. 这篇文章首发于我的个人网站:听说 - https://tasaid.com/,建议在我的个人网站阅读,拥有更好的阅读体验. 这篇 ...
- 探索DOMNode
实现代码 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8& ...
- css3元素简单的闪烁效果(html5 jquery)
css3 Animation: @-webkit-keyframes twinkling{ /*透明度由0到1*/ 0%{ opacity:0; /*透明度为0*/ } 100%{ opacity:1 ...
- 【Java每日一题】20161213
package Dec2016; public class Ques1213 { public static void main(String[] args){ String str1 = " ...
- zigbee 路由节点丢失后清除 该节点的残余网络信息
清除脱离网络的 路由节点(stale device)的 残留在各表中以AssociationDevList为例的残余信息. 如图所示拓扑结构中: 路由器1脱离网络后,通过协调器按键操作来 清除 协调 ...
- Java--JDK动态代理核心源码解析
1.首先我们了解一下JDK动态代理的使用方法: public static void main(String[] args) { /** * 创建一个Bean对象,该对象实现BeanInterFace ...
- 【PHP夯实基础系列】PHP日期,文件系统等知识点
1. PHP时间 1)strtotime() //日期转成时间戳 2) date()//时间戳变成日期 <?php date_default_timezone_set("PRC&quo ...
- 装配bean
spring有三种装配bean的方式:隐式装配.java代码装配.xml装配 隐式装配最为省事方便,也称为自动化装配 这三种装配方式可以混搭着来用 在这里通过一个例子来讲述配置 CD的两个实现,一个是 ...
- RequireJS+JQueryMobile
RequireJS提供了JS下模块化开发的充分条件.之前我自己也在多个项目中尝试模块化开发,但是由于没有类似RequireJS这样的框架,最后的效果都不是很理想. 在RequireJS中,所有的JS都 ...
- How to get Timer Job History
1. Get Timer Job internal name with id. Job ID can be found in SharePoint CA. Below PowerShell can h ...