Beautiful Soup 4.4.0
1. 参考
官方文档:http://beautifulsoup.readthedocs.io/zh_CN/latest/
2. 解压后
目录结构如下:

如果WinZIP解压不了tar.gz,则可以先传到Linux机器上使用 tar 命令解压,然后回传到windows机器上来。
3. 注意事项
1) 电脑先要安装Python,这个可以搜索一下,下载相应的版本!我下载的是3.3.1
2) Python 3.3.1 环境下,build bs4.4会不成功,build bs4.3是成功的!
4. 附录
Windows安装:http://blog.youkuaiyun.com/jenyzhang/article/details/45828481
Python编辑器:Pycharm community Edition IDE
5. 初步尝试
Take action!
6. 爬取子页面数据的Python代码
我又编辑了一下文章,因为已经完成了完整的代码,爬取到了需要的子页面数据,保存到了excel中。开心!又会了一门东西!
链接:http://pan.baidu.com/s/1jHFfdWy
7. 使用到的 Python 语法
7.1 函数定义
def funtion1(param1, param2)
..omit...
return var1;
7.2 流程语句
7.2.1 If..else
a. 判断对象/字符串是否为空
if (var1 is None):
print("var1 is None")
else:
#print("var1 is not None");
b. 判断列表是否为空
if len(list1) == 0:
print("list is empty");
else:
print("list is not empty");
7.2.2 Try..except
异常捕捉
try:
print("this is try clause");
except:
print("handling clause in exception");
finally:
print("finally clause");
7.2.3 For..in
迭代循环
for link in soup.find_all("a[href]"):
href = link["href"]; # also used as link.get("href");
print("href is %s" % (href));
7.3 BeautifulSoup 语法
7.3.1 CSS选择器
soup.select("a[href]") --》 选择带有href属性的<a> tag.
soup.select('div[title*="关键字"]') --》选择 title属性含有 “关键字“ 的<div> tag.