Created
June 14, 2017 22:22
-
-
Save kynan/cfb43671542826a2e3d72c9f26575066 to your computer and use it in GitHub Desktop.
Extract PIDs from BBC iPlayer programme pages
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 | |
"""Extract pids from a BBC iPlayer programme page. | |
usage: get_iplayer --pid $(getbbcpid <url>) | |
""" | |
from __future__ import print_function | |
from bs4 import BeautifulSoup | |
import requests | |
def getpid(url): | |
soup = BeautifulSoup(requests.get(url).text, 'lxml') | |
return ','.join(a.attrs['href'].split('/')[-2] for a in soup.find_all('a') | |
if 'href' in a.attrs and 'episode' in a.attrs['href']) | |
if __name__ == '__main__': | |
from sys import argv | |
print(getpid(argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment