Last active
February 23, 2016 04:10
-
-
Save gazpachoking/28d666bf6e60b30ce3a9 to your computer and use it in GitHub Desktop.
Edit imdb lists programattically
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
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'] = '[email protected]' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All the calls return json, except for the first login stuff.