利用BeautifulSoup抓取网易评论的文章标题,时间,链接
使用BeautifulSoup,request模块,在虚拟的Python2.7下运行
# coding=utf-8
import requests
from bs4 import BeautifulSoup
html = requests.get('http://money.163.com/special/pinglun/')
text = html.text
soup = 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())