第一个BeautifulSoup爬虫

来源:互联网 发布:手机剪辑视频软件知乎 编辑:程序博客网 时间:2024/05/21 12:54

利用BeautifulSoup抓取网易评论的文章标题,时间,链接
使用BeautifulSoup,request模块,在虚拟的Python2.7下运行

# coding=utf-8import requestsfrom bs4 import BeautifulSouphtml = requests.get('http://money.163.com/special/pinglun/')text = html.textsoup = BeautifulSoup(text, "lxml")# h2 = soup.find('h2')# print h2#搜索div标签下所有class为item_top的内容for link in soup.find_all('div', class_='item_top'):    #获得a标签下的文字    print(link.a.get_text())    #获得a标签下href    print(link.a.get('href'))    #获得span标签下的文字,即时间    print(link.span.get_text())
0 0
原创粉丝点击