Beautiful Soup使用

来源:互联网 发布:单农为什么淘宝没有 编辑:程序博客网 时间:2024/06/04 01:36

响应:soup = BeautifulSoup(response.body_as_unicode(), ‘lxml’)
本地:soup = BeautifulSoup(codecs.open(fileName, ‘r’, ‘utf-8’, ‘lxml’)

获取标签的属性

文本 = getText()
id = get(‘id’)
title = get(‘title’)
……

根据class和id选择标签

1.包含id属性

soup.find(class_=”“, id = True)

2.id符合正则格式, id的格式形如”C_123…”,

soup.find(class_=”“, id = re.compile(”C_(.*)”))

0 0
原创粉丝点击