-
Notifications
You must be signed in to change notification settings - Fork 50
/
xunlei2.py
46 lines (39 loc) · 1.25 KB
/
xunlei2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'wei'
import urllib2
import utils
from bs4 import BeautifulSoup
def getXunLeiAccount():
data = []
url = "http://xlfans.com"
html = getPage(url)
soup = BeautifulSoup(html, 'html.parser')
tag_as = soup.find_all("article", class_="excerpt")
html =""
for title in tag_as:
if utils.checkLink(title.get_text())>=0:
html = getPage(title.find_all("a")[0].get('href'))
break
soup = BeautifulSoup(html, 'html.parser')
tag_p = soup.find_all("p")
for line in tag_p:
text = line.get_text().encode('utf-8')
# print(line)
if (text.find("迅雷") >= 0 and text.find("密") >= 0):
dataList = utils.removeChineseChar(text).split(u'\n')
for _data in dataList:
if (len(_data.replace(' ', '')) >= 10):
data.append(_data)
return data
def getPage(url):
'''下载文件html代码,找出一楼的核心代码'''
opener = urllib2.build_opener()
# 不加头信息则出现403错误和乱码
opener.addheaders = [('User-agent', 'Mozilla/5.0')];
htmlAll = opener.open(url).read()
# 文件保存编码和文件编辑编码都是utf-8,所以decode一次,不然会出现乱码,但是不影响结果。
return htmlAll
if __name__ == '__main__':
data = getXunLeiAccount()
utils.showData(data)