服务器之家

服务器之家 > 正文

基于python实现的抓取腾讯视频所有电影的爬虫

时间:2020-08-20 10:14     来源/作者:Python教程网

我搜集了国内10几个电影网站的数据,里面近几十W条记录,用文本没法存,mongodb学习成本非常低,安装、下载、运行起来不会花你5分钟时间。

?
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: utf-8 -*-
# by awakenjoys. my site: www.dianying.at
import re
import urllib2
from bs4 import BeautifulSoup
import string, time
import pymongo
 
NUM  = 0   #全局变量,电影数量
m_type = u''  #全局变量,电影类型
m_site = u'qq' #全局变量,电影网站
 
#根据指定的URL获取网页内容
def gethtml(url):
 req = urllib2.Request(url)
 response = urllib2.urlopen(req)
 html = response.read()
 return html
 
#从电影分类列表页面获取电影分类
def gettags(html):
 global m_type
 soup = BeautifulSoup(html)  #过滤出分类内容
 #print soup
 #<ul class="clearfix _group" gname="mi_type" gtype="1">
 tags_all = soup.find_all('ul', {'class' : 'clearfix _group' , 'gname' : 'mi_type'})
 #print len(tags_all), tags_all
 #print str(tags_all[1]).replace('\n', '')
 
 #<a _hot="tag.sub" class="_gtag _hotkey" href="http://v.qq.com/list/1_0_-1_-1_1_0_0_20_0_-1_0.html" id="codetool">

相关文章

热门资讯

返回顶部