用python实现的抓取腾讯视频所有电影的爬虫
# -*- coding: utf-8 -*-
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