Skip to content

Instantly share code, notes, and snippets.

@gazpachoking
Last active February 23, 2016 04:10
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 gazpachoking/28d666bf6e60b30ce3a9 to your computer and use it in GitHub Desktop.
Save gazpachoking/28d666bf6e60b30ce3a9 to your computer and use it in GitHub Desktop.
Edit imdb lists programattically
import requests
from bs4 import BeautifulSoup
sess = requests.Session()
r = sess.get('https://www.imdb.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.imdb.com%2Fap-signin-handler&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=imdb_mobile_us&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0')
soup = BeautifulSoup(r.content, 'html5lib')
inputs = soup.select('form#ap_signin_form input')
data = dict((i.get('name'), i.get('value')) for i in inputs if i.get('name'))
data['email'] = 'your@email.com'
data['password'] = 'aoeu'
sess.post('https://www.imdb.com/ap/signin', data=data)
# Try to get imdb urls that require sign in now
# Check movie is in watchlist, get the list id and item id and extra param needed for removing
data = {'consts[]': 'tt0805570', 'tracking_tag': 'watchlistRibbon'}
r = sess.post('http://www.imdb.com/list/_ajax/watchlist_has', data=data)
# Add to watchlist
data = {
'const': 'imdb id',
'list_id': '', # provided by watchlist_has
'ref_tag': 'title',
'list_class': 'WATCHLIST',
'extraParamName': 'extraParamValue' # provided by watchlist_has
}
sess.post('http://www.imdb.com/list/_ajax/edit', data=data)
# Remove from watchlist
data = {
'action': 'delete',
'list_id': '', # provided by watchlist_has
'list_item_id': '', # provided by watchlist_has
'ref_tag': 'title',
'list_class': 'WATCHLIST',
'extraParamName': 'extraParamValue' # provided by watchlist_has
}
# See if a title is in custom lists
data = {'tconst': 'imdb id'}
sess.post('http://www.imdb.com/list/_ajax/wlb_dropdown', data=data) # Gives you list ids, and item ids, if movie is in list
# Adding and removing are now the same as for watchlist, but 'list_class' and the extra parameter are not needed
@gazpachoking
Copy link
Author

All the calls return json, except for the first login stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment