OAuthBrowser是进行身份验证和web抓取的模块。
OAuthBrowser的Python项目详细描述
OAuthBrowser
此模块将允许您通过系统浏览器对OAuth 2.0进行身份验证并获得响应URL。目前支持Google Chrome和Safari浏览器。用applescript和osascript构建,仅适用于macosx。在
使用OAuthBrowser可以做更多的事情,比如不需要从网站自动检测就可以获得源代码。在
安装
使用包管理器pip安装OAuthBrowser。在
pip install OAuthBrowser
或者从这里安装最新的回购。在
^{pr2}$使用
用法非常简单
- 传递身份验证URL。在
- 应用
Wait
类等待浏览器重定向。在 - 获取URL。在
- 关闭浏览器。在
fromOAuthBrowserimportSafari,Waitfromurllib.parseimporturlparse,parse_qsURL="""https://accounts.google.com/signin/oauth/oauthchooseaccount?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&state=state_parameter_passthrough_value&redirect_uri=https%3A%2F%2Foauth2.example.com%2Fcode&access_type=offline&response_type=code&client_id=583306224539-atbcaa8ne8g85e8kc006o6vmq99qiid0.apps.googleusercontent.com&o2v=2&as=CDdm3G6Zd1UOG9o_gWXzQQ&flowName=GeneralOAuthFlow"""# Initialise browserbrowser=Safari(window_geometry=(100,22,400,690))# Pass Authentication URLbrowser.open_new_window(URL)# Initialise Waitwait=Wait(browser)# Wait till query "code" is present in the URL.wait.until_present_query('code')# Fetch the urlresponse_url=urlparse(browser.get_current_url())code=parse_qs(response_url.query).get('code')[0]print("\nCode: %s\n"%code)# Close the browserbrowser.quit()
示范
python -m OAuthBrowser
贡献
向此存储库投稿时,请先讨论您希望通过问题、电子邮件或此存储库的任何其他方法进行的更改,然后再进行更改。在
请确保根据需要更新测试。在
许可证
变更日志
- 0.0.1
- 第一次导入。在
- 项目
标签: