python批量获取Youtube专辑中视频地址

作者:stoat 发布时间:2014-02-12 分类:闲扯

电脑没开全局代理的话,默认Youtube网址是访问不了的,所以就直接把相关链接丢到1.txt文件中就行了。相关Python代码如下:


import re
import urllib
u = '1.txt'
page = urllib.urlopen(u)
html = page.read()
page.close()
str = html
zz = 'href=".+?" title'
reg= re.compile(zz)
obj = reg.findall(str)
for i in obj:
	i = i[6:-51]
	i = 'https://www.youtube.com' + i
	print i

如果开了全局代理能够访问Youtube网址,就使用以下python脚本即可。

import re
import urllib

u = 'https://www.youtube.com/playlist?list=PLLjmbh6XPGK4rR2Fo7SzuyBIKFnDh8emj'#youtube palylist url
page = urllib.urlopen(u)
html = page.read()
page.close()
a = html.find(r'id="gh-activityfeed">')
b = html.find(r'
') str = html[a:b] zz = 'href=".+?" title' reg= re.compile(zz) obj = reg.findall(str) x = 0 for str in obj: x+=1 if(x % 2 == 0): i = re.sub(r'&.*title','',str) i = i[6:] i = 'https://www.youtube.com' + i print i

当然了,可以写个代理加入header请求,但是,懒得搞了。

原文地址:python批量获取Youtube专辑中视频地址 by 雪鼬博客

标签:youtube Python

仅有一条评论 »

  1. skybox F3 skybox F3

    Original Skybox F3 HD digital satellite receiver, full 1080pi support usb wifi, supported by cccam and newcam, watch YouTube YouPorn with skybox f3 is just an easy thing.

评论已关闭