我現在正在使用它的api在新浪微博爬蟲上開玩笑。 爲了使用api,我必須訪問oauth2授權頁面才能從url中檢索代碼。如何解析響應url而不實際打開python中的網頁?
這正是我該怎麼做:
使用我APP_KEY和app_secret(均爲已知)
得到的oauth2網頁
複製的URL粘貼從響應代碼手動URL。
這是我的代碼:
#call official SDK
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
#get url of callback page of authorization
url = client.get_authorize_url()
print url
#open webpage in browser
webbrowser.open_new(url)
#after the webpage responding, parse the code part in the url manually
print 'parse the string after 'code=' in url:'
code = raw_input()
我的問題是究竟如何擺脫手動解析部分的?
參考: http://blog.csdn.net/liuxuejiang158blog/article/details/30042493
看看['requests'](http://docs.python-requests.org/en/master/)模塊 –