大数据分析就不会了,还请赐教。
import requests
from bs4 import BeautifulSoup
r = requests.get("http://club.mil.news.sina.com.cn/thread-666013-1-1.html")
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text)
result = soup.find(attrs={"class": "cont f14"})
print result.text
用beautifulSoup吧,正则太多了看着都头疼.
先用了BeautifulSoup爬取数据# -*- coding:utf-8 -*-
import re, requests
from bs4 import BeautifulSoup
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
url = "http://club.mil.news.sina.com.cn/viewthread.php?tid=666013&extra=page%3D1&page=1"
req = requests.get(url)
req.encoding = req.apparent_encoding
html = req.text
soup = BeautifulSoup(html)
file = open('sina_club.txt', 'w')
x = 1
for tag in soup.find_all('div', attrs = {'class': "cont f14"}):
word = tag.get_text()
line1 = "---------------评论" + str(x) + "---------------------" + "\n"
line2 = word + "\n"
line = line1 + line2
x += 1
file.write(line)
file.close()
哎,扒就扒吧,发了paper能不能告诉我刊号页数让我看一下?我们自己都没做大数据分析……
建议用一下正则测试工具
你需要pyquery,可以使用jquery一样的语法。你值得拥有。https://pythonhosted.org/pyquery/