分享一段tornado登陆豆瓣的代码,只简单实现了登陆,并没有实现异步登陆。需要的网友可以自己将代码完善一下。
直接上代码:
#coding=utf8 import settings import urllib from tornado import httpclient import json class douban: authurl = 'https://www.douban.com/service/auth2/' user_info_url = 'https://api.douban.com/v2/user/~me' def get_authorization_code(self): params = { "client_id":settings.oauth2['douban']['key'], "redirect_uri":settings.oauth2['redirect_url'], "response_type":"code", "scope":"douban_basic_common", } return self.authurl+'auth?'+urllib.urlencode(params) def get_access_token(self,code): params = { "client_id":settings.oauth2['douban']['key'], "client_secret":settings.oauth2['douban']['sercet'], "redirect_uri":settings.oauth2['redirect_url'], "grant_type":"authorization_code", "code":code, } url = self.authurl+'token' http_client = httpclient.HTTPClient() req = httpclient.HTTPRequest(url,method='POST',body=urllib.urlencode(params)) response = http_client.fetch(req) return json.loads(response.body) def get_user_info(self,access_token): url = 'https://api.douban.com/v2/user/~me' http_client = httpclient.HTTPClient() req = httpclient.HTTPRequest(url,headers={"Authorization":"Bearer "+access_token}) response = http_client.fetch(req) return json.loads(response.body)

Linux终端中查看Python版本时遇到权限问题的解决方法当你在Linux终端中尝试查看Python的版本时,输入python...

本文解释了如何使用美丽的汤库来解析html。 它详细介绍了常见方法,例如find(),find_all(),select()和get_text(),以用于数据提取,处理不同的HTML结构和错误以及替代方案(SEL)

本文比较了Tensorflow和Pytorch的深度学习。 它详细介绍了所涉及的步骤:数据准备,模型构建,培训,评估和部署。 框架之间的关键差异,特别是关于计算刻度的

在使用Python的pandas库时,如何在两个结构不同的DataFrame之间进行整列复制是一个常见的问题。假设我们有两个Dat...

本文讨论了诸如Numpy,Pandas,Matplotlib,Scikit-Learn,Tensorflow,Tensorflow,Django,Blask和请求等流行的Python库,并详细介绍了它们在科学计算,数据分析,可视化,机器学习,网络开发和H中的用途

本文指导Python开发人员构建命令行界面(CLIS)。 它使用Typer,Click和ArgParse等库详细介绍,强调输入/输出处理,并促进用户友好的设计模式,以提高CLI可用性。

文章讨论了虚拟环境在Python中的作用,重点是管理项目依赖性并避免冲突。它详细介绍了他们在改善项目管理和减少依赖问题方面的创建,激活和利益。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver Mac版
视觉化网页开发工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1
好用且免费的代码编辑器