利用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())
本文介绍了一种使用Python中的BeautifulSoup和requests模块从网易财经页面抓取文章标题、发布时间及链接的方法。通过解析网页源代码,可以批量获取指定区域内的新闻信息。
1967

被折叠的 条评论
为什么被折叠?



