前言
本文的文字及圖片來源於網絡,僅供學習、交流使用,不具備任何商業用途,版權歸原做者全部,若有問題請及時聯繫咱們以做處理。
做者: Python新手學習之家
html
用python實現的抓取騰訊視頻全部電影的爬蟲python

-
-
-
-
from bs4 import BeautifulSoup
-
-
-
-
-
-
-
-
-
-
req = urllib2.Request(url)
-
response = urllib2.urlopen(req)
-
-
-
-
在學習過程當中有什麼不懂得能夠加個人python學習交流扣扣qun,934109170,羣裏有不錯的學習教程與開發工具。
-
-
-
-
-
-
soup = BeautifulSoup(html)
-
-
-
tags_all = soup.find_all(
'ul', {'class' : 'clearfix _group' , 'gname' : 'mi_type'})
-
-
-
-
-
re_tags =
r'<a _hot=\"tag\.sub\" class=\"_gtag _hotkey\" href=\"(.+?)\" title=\"(.+?)\" tvalue=\"(.+?)\">.+?</a>'
-
p = re.compile(re_tags, re.DOTALL)
-
-
tags = p.findall(str(tags_all[
0]))
-
-
-
-
-
tag_url = tag[
0].decode('utf-8')
-
-
m_type = tag[
1].decode('utf-8')
-
tags_url[m_type] = tag_url
-
-
-
-
-
-
-
-
tag_html = gethtml(tag_url)
-
-
soup = BeautifulSoup(tag_html)
-
-
-
div_page = soup.find_all(
'div', {'class' : 'mod_pagenav', 'id' : 'pager'})
-
-
-
-
re_pages =
r'<a class=.+?><span>(.+?)</span></a>'
-
p = re.compile(re_pages, re.DOTALL)
-
pages = p.findall(str(div_page[
0]))
-
-
-
-
-
-
-
-
-
soup = BeautifulSoup(html)
-
-
-
divs = soup.find_all(
'ul', {'class' : 'mod_list_pic_130'})
-
-
-
div_html = str(div_html).replace(
'\n', '')
-
-
-
-
-
-
-
-
-
-
re_movie =
r'<li><a class=\"mod_poster_130\" href=\"(.+?)\" target=\"_blank\" title=\"(.+?)\"><img.+?</li>'
-
p = re.compile(re_movie, re.DOTALL)
-
-
-
conn = pymongo.Connection(
'localhost', 27017)
-
-
playlinks = movie_db.playlinks
-
-
-
-
-
print "%s : %d" % ("=" * 70, NUM)
-
-
-
-
-
-
-
-
-
-
-
print "%s : %d" % ("=" * 70, NUM)
-
-
-
-
-
-
-
soup = BeautifulSoup(html)
-
-
-
divs = soup.find_all(
'div', {'class' : 'pack pack_album album_cover'})
-
-
-
-
re_info =
r'<a href=\"(.+?)\" target=\"new\" title=\"(.+?)\" wl=\".+?\"> </a>'
-
p_info = re.compile(re_info, re.DOTALL)
-
m_info = p_info.findall(str(divs[
0]))
-
-
-
-
print "Not find movie info"
-
-
-
-
-
-
-
movie_db = conn.dianying_at
-
-
-
-
if __name__ == "__main__":
-
-
-
tags_url =
"http://v.qq.com/list/1_-1_-1_-1_1_0_0_20_0_-1_0.html"
-
-
tags_html = gethtml(tags_url)
-
-
tag_urls = gettags(tags_html)
-
-
-
-
for url in tag_urls.items():
-
print str(url[1]).encode('utf-8')
-
maxpage = int(get_pages(str(url[
1]).encode('utf-8')))
-
-
-
for x in range(0, maxpage):
-
-
m_url = str(url[
1]).replace('0_20_0_-1_0.html', '')
-
movie_url =
"%s%d_20_0_-1_0.html" % (m_url, x)
-
-
movie_html = gethtml(movie_url.encode(
'utf-8'))
-
-
-
大工告成,以上代碼你們都看明白了沒? 若是你看不懂,建議你能夠去小編的Python交流.裙 :一久武其而而流一思(數字的諧音)轉換下能夠找到了,裏面有最新Python教程項目,多練習天然就懂了!