admin管理员组

文章数量:1530085

用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  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"  href="http://v.qq/list/1

本文标签: 爬虫腾讯电影视频Python