python爬虫编码问题

Python015

python爬虫编码问题,第1张

<span style="font-size:18px">./s //在终端中运行程序

Current directory is :/home/talk8/CExample //通过API得到当前工作目录

./s pwd //在终端中运行程序,第二个参数是pwd,表示让程序执行pwd命令

/home/talk8/CExample //通过execlp得到当前工作目录

1:安装python(这个不多说啦)

2:下载新浪微博SDK的python包,解压为weibopy目录

3:申请AppKey,

流程:

1:通过oAuth认证

按我的理解简化如下:

用户在新浪微博给的页面输入账号密码,然后微博给应用一个PIN码,这样应用通过PIN码才有权限访问该用户的信息,而应用在整个过程中是接触不到密码的,所以用户觉得很安全,后果很满意

2:获得认证之后,就可以使用微博SDK提供的API获得信息啦

3:如果想设计web或者客户端应用的话,那就继续加个GUI好啦(未完成)

代码:

#!/usr/bin/python

import webbrowser

from weibopy.auth import OAuthHandler

from weibopy.api import API

AppKey = '2525355147'

AppSecret = '2e2c7bcdfc362eace266d1f2bf83fe6b'

my_auth = OAuthHandler(AppKey , AppSecret)

webbrowser.open(my_auth.get_authorization_url())

verifier = raw_input('PIN: ').strip()

my_auth.get_access_token(verifier)

my_api = API(my_auth)

for comment in my_api.mentions():

object = comment

id = object.__getattribute__("id")

text = object.__getattribute__("text")

print str(id) + " : " + text