Skip to content

Instantly share code, notes, and snippets.

@kynan
Created June 14, 2017 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kynan/cfb43671542826a2e3d72c9f26575066 to your computer and use it in GitHub Desktop.
Save kynan/cfb43671542826a2e3d72c9f26575066 to your computer and use it in GitHub Desktop.
Extract PIDs from BBC iPlayer programme pages
#!/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