爬虫利器BeautifulSoup模块使用
| 一、简介 |
BeautifulSoup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式,同时应用场景也是非常丰富,你可以使用它进行XSS过滤,也可以是使用它来提取html中的关键信息。
官方文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc/
| 二、安装 |
1.安装模块
easy_install beautifulsoup4
pip3 install beautifulsoup4
2.安装解析器(可以使用内置的解析器)
#Ubuntu
$ apt-get install Python-lxml
#centos/redhat
$ easy_install lxml
$ pip install lxml
3.各个解释器优缺点比较

| 三、开始使用,基本属性介绍 |
创建对象
将一段文档传入BeautifulSoup 的构造方法,就能得到一个文档的对象, 可以传入一段字符串或一个文件句柄。
from bs4 import BeautifulSoup
soup = BeautifulSoup(open("index.html"))
soup = BeautifulSoup("<html><body>...</body></html>")
###使用解释器###
soup = BeautifulSoup(open("index.html"), features="lxml")
基本使用
使用html示例
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><b>wd</b></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
""" soup=BeautifulSoup(html_doc,features="html.parser")
print(soup.head)#获取head标签
print(soup.head.title)#获取title
print(soup.body.a)
tips:通过soup.方式获取的标签如果标签有多个,只返回第一个标签
1.name:标签名称,如:<a>标签的名称为a,<span>标签名称为span
操作方式:获取、设置,设置以后会使得原文档标签改变
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><b>wd</b></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
print(soup.body.name)#获取标签名称
soup.body.p.name='span'#设置标签名称
print(soup)
2.attrs:标签属性(如id,class,style等)
操作方式:获取、设置
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><b>wd</b></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
print(soup.body.p.attrs)#获取标签所有属性
soup.body.p.attrs['id']='user'#设置/添加属性
print(soup.body.p.attrs.get('class'))#获取标签具体的某个属性,当然可以通过soup.body.p.attrs['class']获取
soup.body.p.attrs['class']=["hide","a1"]#设置多个属性
print(soup)
3.string:标签内容(类似js中的innertext),该属性只能适用于标签中只有一个内容,若有多个子标签都有内容则返回None
操作方式:获取、设置
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><b>wd</b></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
print(soup.head.title.string)#获取内容
soup.head.title.string='name'#设置内容
print(soup)
4.contents:将子节点以列表方式输出,返回list(),列表中仅仅含有子标签
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><a>wd</a></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
a=soup.body.contents
print(a)
print(type(a))
5.childen:和contents不同,它返回列表生成器,使用循环获取,生成器中只含有子标签
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><a>wd</a></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
a=soup.body.children
print(type(a))
for item in a:
print(item)
6.descendants:返回子子孙孙标签,返回迭代器
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><a>wd</a></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
a=soup.body.descendants
print(type(a))
for k,v in enumerate(a):
print(k,v)
7.strings&stripped_strings:返回所有子子孙孙标签内容生成器,stripped_strings和strings区别是,stripped_strings输出的是去掉空格的内容。
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><b>wd</b></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
""" soup=BeautifulSoup(html_doc,features="html.parser")
for k,v in enumerate(soup.body.strings):
print(k,v)
for k1,v1 in enumerate(soup.body.stripped_strings):
print(k1,v1)
复制代码
8.parent&parents:父标签(节点)和祖辈节点,父标签一般只有一个,祖辈节点可能很多,parents返回生成器。
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><a>wd</a></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
""" soup=BeautifulSoup(html_doc,features="html.parser")
print(soup.a.parent)#a标签的父节点
b=list(enumerate(soup.a.parents))
print(b)
for k,v in enumerate(soup.a.parents): #a标签的祖辈节点
print(k,v)
9.next_sibling&previous_sibling:兄弟标签(节点),一般只有一个,没有返回none
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><a>wd</a></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
""" soup=BeautifulSoup(html_doc,features="html.parser")
print(soup.p.next_sibling)
print(soup.p.previous_sibling)
for k,v in enumerate(soup.p.next_siblings):
print(k,v)
10.next_siblings&previous_siblings:返回所有兄弟标签的生成器。
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>test</title></head>
<body>
<p class="title"><a>wd</a></p>
<p class="story">
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
</p>
<p class="story">...</p>
</body>
</html>
""" soup=BeautifulSoup(html_doc,features="html.parser")
for k,v in enumerate(soup.p.next_siblings):
print(k,v)
for k1,v1 in enumerate(soup.p.previous_siblings):
print(k1,v1)
11.hidden:隐藏或显示当前标签,只会把当前标签隐藏,子孙标签不变
soup=BeautifulSoup(html_doc,features="html.parser")
tag = soup.find('body')
tag.hidden=True#设置body标签隐藏
print(tag)
print(soup)
12.is_empty_element,是否是空标签(是否可以是空)或者自闭合标签
# tag = soup.find('br')
# v = tag.is_empty_element
# print(v)
| 四、强大的过滤器 |
这里所说的过滤器可以理解为查找文档的参数,可以是字符串,可以是name,可以是正则表达式等等,过滤器依赖于过滤方法,下面介绍常用过滤方法。
1.find_all(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs): 获取匹配的所有标签(节点),返回列表
- name:标签名,字符串对象会被忽略,可以是字符串、正则、列表、方法或者True
- attrs:标签属性,字典形式,用于查找标签的特殊属性
- recursive:是否递归查找,设置Flase,只查找子节点.
- text:文档中的字符串内容,与name参数一样,可接受字符串、正则、列表、或者True
- limit:限制列表中个数,如limit=3只返回前三个
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
asdf
<div class="title">
<b>The Dormouse's story总共</b>
<h1>f</h1>
</div>
<div class="story">Once upon a time there were three little sisters; and their names were
<a class="sister0" id="link1">Els<span>f</span>ie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</div>
ad<br/>sf
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
# tags = soup.find_all('a')
# print(tags) # tags = soup.find_all('a',limit=1)
# print(tags) # tags = soup.find_all(name='a', attrs={'class': 'sister'}, recursive=True, text='Lacie')
# # tags = soup.find(name='a', class_='sister', recursive=True, text='Lacie')
# print(tags) # ####### 列表 #######
# v = soup.find_all(name=['a','div'])
# print(v) # v = soup.find_all(class_=['sister0', 'sister'])
# print(v) # v = soup.find_all(text=['Tillie'])
# print(v, type(v[0])) # v = soup.find_all(id=['link1','link2'])
# print(v) # v = soup.find_all(href=['link1','link2'])
# print(v) # ####### 正则 #######
import re
# rep = re.compile('p')
# rep = re.compile('^p')
# v = soup.find_all(name=rep)
# print(v) # rep = re.compile('sister.*')
# v = soup.find_all(class_=rep)
# print(v) # rep = re.compile('http://www.oldboy.com/static/.*')
# v = soup.find_all(href=rep)
# print(v) # ####### 方法筛选 #######
# def func(tag):
# return tag.has_attr('class') and tag.has_attr('id')
# v = soup.find_all(name=func)
# print(v) # ## get,获取标签属性
# tag = soup.find('a')
# v = tag.get('id')
# print(v)
2.find_all(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs): 获取匹配的一个(节点),返回tag对象,用法与find_all相同
#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
asdf
<div class="title">
<b>The Dormouse's story总共</b>
<h1>f</h1>
</div>
<div class="story">Once upon a time there were three little sisters; and their names were
<a class="sister0" id="link1">Els<span>f</span>ie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</div>
ad<br/>sf
<p class="story">...</p>
</body>
</html>
"""
soup=BeautifulSoup(html_doc,features="html.parser")
tag = soup.find('a')
print(tag.name)
3.其他过滤方法:
tag.find_next(...) #返回后面第一个符合条件的节点
tag.find_all_next(...) #返回后面所有符合条件的节点
tag.find_next_sibling(...) #返回后面第一个兄弟节点
tag.find_next_siblings(...) #返回后面所有兄弟节点 tag.find_previous(...) #返回前面一个符合条件的节点
tag.find_all_previous(...) #返回前面所有符合条件的节点
tag.find_previous_sibling(...) #返回前面第一个兄弟节点
tag.find_previous_siblings(...) #返回前面所有兄弟节点 tag.find_parent(...) #返回所有祖先节点
tag.find_parents(...) #返回直接父节点 # 参数同find_all
| 五、CSS选择器 |
BeautifulSoup不仅提供了筛选器,也提供了选择器,用法和前端css一样,其中.代表class,#代表id
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
asdf
<div class="title">
<b>The Dormouse's story总共</b>
<h1>f</h1>
</div>
<div class="story">Once upon a time there were three little sisters; and their names were
<a class="sister0" id="link1">Els<span>f</span>ie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</div>
ad<br/>sf
<p class="story">...</p>
</body>
</html>
""" soup = BeautifulSoup(html_doc, features="lxml")
soup.select("title") soup.select("p nth-of-type(3)") soup.select("body a") soup.select("html head title") tag = soup.select("span,a") soup.select("head > title") soup.select("p > a") soup.select("p > a:nth-of-type(2)") soup.select("p > #link1") soup.select("body > a") soup.select("#link1 ~ .sister") soup.select("#link1 + .sister") soup.select(".sister") soup.select("[class~=sister]") soup.select("#link1") soup.select("a#link2") soup.select('a[href]') soup.select('a[href="http://example.com/elsie"]') soup.select('a[href^="http://example.com/"]') soup.select('a[href$="tillie"]') soup.select('a[href*=".com/el"]') from bs4.element import Tag def default_candidate_generator(tag):
for child in tag.descendants:
if not isinstance(child, Tag):
continue
if not child.has_attr('href'):
continue
yield child tags = soup.find('body').select("a", _candidate_generator=default_candidate_generator)
print(type(tags), tags) from bs4.element import Tag
def default_candidate_generator(tag):
for child in tag.descendants:
if not isinstance(child, Tag):
continue
if not child.has_attr('href'):
continue
yield child tags = soup.find('body').select("a", _candidate_generator=default_candidate_generator, limit=1)
print(type(tags), tags)
| 六、tag对象常用方法 |
1.clear():将标签的所有子标签全部清空(保留标签名)
# tag = soup.find('body')
# tag.clear()
# print(soup)
2.decompose():递归的删除所有的标签
soup=BeautifulSoup(html_doc,features="html.parser")
body = soup.find('body')
body.decompose()#body自身标签也会删除
print(soup)
3.extract():递归的删除所有的标签,并获取删除的标签
soup=BeautifulSoup(html_doc,features="html.parser")
body = soup.find('body')
a=body.extract()
print(a)
print(soup)
4.decode()&decode_contents():decode,转换为字符串(含当前标签),decode_contents(不含当前标签)
soup=BeautifulSoup(html_doc,features="html.parser")
body = soup.find('body')
a=body.decode()
b=body.decode_contents()
print(type(a))
print(type(b))
5.encode()&encode_contents():encode,转换为bytes类型(含当前标签),encode_contents(不含当前标签)
soup=BeautifulSoup(html_doc,features="html.parser")
body = soup.find('body')
a=body.encode()
b=body.encode_contents()
print(type(a))
print(type(b))
6. has_attr():检查标签是否具有该属性,返回布尔类型
soup=BeautifulSoup(html_doc,features="html.parser")
tag = soup.find('a')
print(tag.has_attr('id'))
7. get_text():获取标签内部文本内容
soup=BeautifulSoup(html_doc,features="html.parser")
tag = soup.find('a')
print(tag.get_text())
8.index():检查标签在某标签中的索引位置
# tag = soup.find('body')
# v = tag.index(tag.find('div'))
# print(v)
# tag = soup.find('body')
# for i,v in enumerate(tag):
# print(i,v)
9.append():在当前标签内部追加一个标签
# tag = soup.find('body')
# tag.append(soup.find('a'))
# print(soup)
#
# from bs4.element import Tag
# obj = Tag(name='i',attrs={'id': 'it'})
# obj.string = '我是一个新来的'
# tag = soup.find('body')
# tag.append(obj)
# print(soup)
10.insert():在当前标签内部指定位置插入一个标签
# from bs4.element import Tag
# obj = Tag(name='i', attrs={'id': 'it'})
# obj.string = '我是一个新来的'
# tag = soup.find('body')
# tag.insert(2, obj)
# print(soup)
11.insert_after()&insert_before(): 在当前标签后面或前面插入
# from bs4.element import Tag
# obj = Tag(name='i', attrs={'id': 'it'})
# obj.string = '我是一个新来的'
# tag = soup.find('body')
# # tag.insert_before(obj)
# tag.insert_after(obj)
# print(soup)
12.replace_with(): 在当前标签替换为指定标签
# from bs4.element import Tag
# obj = Tag(name='i', attrs={'id': 'it'})
# obj.string = '我是一个新来的'
# tag = soup.find('div')
# tag.replace_with(obj)
# print(soup)
13.setup():设置标签之间关系
# tag = soup.find('div')
# a = soup.find('a')
# tag.setup(previous_sibling=a)
# print(tag.previous_sibling)
14.wrap():将指定标签把当前标签包裹起来
# from bs4.element import Tag
# obj1 = Tag(name='div', attrs={'id': 'it'})
# obj1.string = '我是一个新来的'
#
# tag = soup.find('a')
# v = tag.wrap(obj1)
# print(soup) # tag = soup.find('a')
# v = tag.wrap(soup.find('p'))
# print(soup)
15. unwrap():去掉当前标签,将保留其包裹的标签
# tag = soup.find('a')
# v = tag.unwrap()
# print(soup)
爬虫利器BeautifulSoup模块使用的更多相关文章
- 【爬虫入门手记03】爬虫解析利器beautifulSoup模块的基本应用
[爬虫入门手记03]爬虫解析利器beautifulSoup模块的基本应用 1.引言 网络爬虫最终的目的就是过滤选取网络信息,因此最重要的就是解析器了,其性能的优劣直接决定这网络爬虫的速度和效率.Bea ...
- 【网络爬虫入门03】爬虫解析利器beautifulSoup模块的基本应用
[网络爬虫入门03]爬虫解析利器beautifulSoup模块的基本应用 1.引言 网络爬虫最终的目的就是过滤选取网络信息,因此最重要的就是解析器了,其性能的优劣直接决定这网络爬虫的速度和效率.B ...
- Python 爬虫三 beautifulsoup模块
beautifulsoup模块 BeautifulSoup模块 BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,之后遍可以使用他提供的方法进行快速查 ...
- Python爬虫之Beautifulsoup模块的使用
一 Beautifulsoup模块介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Be ...
- Python网络爬虫之BeautifulSoup模块
一.介绍: Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮 ...
- 爬虫五 Beautifulsoup模块
一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你 ...
- 爬虫五 Beautifulsoup模块详细
一.基本使用 from bs4 import BeautifulSoup htmlCharset = "GB2312" soup=BeautifulSoup(html_doc,'l ...
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
本次python爬虫百步百科,里面详细分析了爬虫的步骤,对每一步代码都有详细的注释说明,可通过本案例掌握python爬虫的特点: 1.爬虫调度入口(crawler_main.py) # coding: ...
- SuperSpider——打造功能强大的爬虫利器
SuperSpider——打造功能强大的爬虫利器 1.爬虫的介绍 图1-1 爬虫(spider) 网络爬虫(web spider)是一个自动的通过网络抓取互联网 上的网页的程序,在当今互联网 中 ...
随机推荐
- Python的locals()函数
Python的locals()函数会以dict类型返回当前位置的全部局部变量. 示例代码: def func(): arg_a, arg_b = 'a', 'b' def func_a(): pass ...
- CSS3 Media Queries 特性的妙用
第一招: 在网页中,pixel与point比值称为 device-pixel-ratio,普通设备都是1,iPhone 4是2,有些Android机型是1.5. 那么-webkit-min-devic ...
- Nginx中并发性能相关配置参数说明
worker_processes:开启worker进程的数目,通常可设置为CPU核心的倍数.在不清楚的情况下,可设置成一倍于CPU核心数或auto(Nginx将自动发现CPU核心数). worker_ ...
- 自学Aruba1.3-WLAN一些基本常识802.11n速率计算方式、802.11n及802.11AC速率表
点击返回:自学Aruba之路 自学Aruba1.3-WLAN一些基本常识802.11n速率计算 1. 802.11n速率计算方式1.1 802.11n使用的主要技术 802.11n采用MIMO多天线技 ...
- 【KMP模板】简单写个KMP~
本来easy的KMP 却一直过不了洛谷的模板题... 仔细一看原来在输出next数组时打的回车而不是空格... 身败名裂... 话说有个sunday貌似一般状况下比KMP快呢...去看看2333 #i ...
- css中的相对定位与绝对定位
之前说过了CSS有三种基本的布局机制:普通流.浮动和绝对定位.除非专门指定,否则所有的框都在普通流中定位.而普通流中元素框的位置由元素在HTML中的位置决定. 相对定位 相对定位实际上被看做普通流定位 ...
- 学习总结:工程管理与makefile
工程管理与makefile 一.为什么需要makefile和make 一个工程中的源文件可能很多,按照类型.功能.模块分别放在若干个目录中,为了有效地管理软件工程,更高效地编译整个工程,需要用到mak ...
- C#学习笔记-适配器模式
什么是适配器模式? 适配器模式(Adapter):将一个类的接口转换成客户希望的另外一个接口. Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 什么时候运用适配器模式? ...
- 使用JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了为 maxJsonLength属性
"/"应用程序中的服务器错误.使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错.字符串的长度超过了为 maxJsonLength 属性设置的值. ...
- AtCoder Regular Contest 069 D
D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...