Last active
December 27, 2015 05:09
-
-
Save mitmul/7272285 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from selenium import webdriver | |
| import re | |
| # 取得する年齢層と性別と値域 | |
| age = '18-24' | |
| gen = 'male' | |
| loc = 'jpn' # '--'だとアメリカ | |
| # ブラウザ起動 | |
| driver = webdriver.Firefox() | |
| url = 'http://www.youtube.com/trendsdashboard#age0=' + \ | |
| age + '&gen0=' + gen + '&loc0=' + loc | |
| driver.get(url) | |
| # 動画URL抽出 | |
| html = driver.page_source.encode('utf-8') | |
| r = re.compile("/watch\?.+\>") | |
| m = r.findall(html) | |
| # ダブるので奇数番目だけ | |
| for url in m[0::2]: | |
| print 'http://www.youtube.com' + url[:-2] | |
| driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment