<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ?在文章[《?Python:通過命令行發送新浪微博》](http://blog.csdn.net/dyx1024/article/details/7237823#reply)中有朋友多次留言咨詢用戶粉絲列表獲取的方法,本來不打算在寫這方面的東東,但出于程序員的特有的執著,還是寫一了一下。這位朋友提供了一個鏈接[點擊打開鏈接](http://www.cnblogs.com/coucar/archive/2011/09/14/2176456.html),其中指定了weiapi(python版本的一個缺陷),參考其先修改了下API,改后如下: parsers.py中ModelParser類的parse方法,如果你的和下面不一樣,請參考修改。 ~~~ class ModelParser(JSONParser): def __init__(self, model_factory=None): JSONParser.__init__(self) self.model_factory = model_factory or ModelFactory def parse(self, method, payload): try: if method.payload_type is None: return model = getattr(self.model_factory, method.payload_type) except AttributeError: raise WeibopError('No model for this payload type: %s' % method.payload_type) json = JSONParser.parse(self, method, payload) if isinstance(json, tuple): json, cursors = json elif isinstance(json, dict): if 'next_cursor' in json: cursors = json['next_cursor'] else: cursors = None else: cursors = None if method.payload_list: result = model.parse_list(method.api, json) else: result = model.parse(method.api, json) if cursors: return result, cursors else: return result ~~~ 2、獲取列表,提供一個你要獲取的用戶id即可,例如我的微博ID:2601091753,用戶名:沒耳朵的羊,關注用戶為71人,粉絲8人(悲催至極啊),如下: ![](https://box.kancloud.cn/2016-06-08_5757935b64412.jpg) 3、實現代碼: ~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- from weibopy.auth import OAuthHandler from weibopy.api import API import ConfigParser import time MAX_PIC_NUM = 5 SLEEP_TIME_LONG = 30 def press_sina_weibo(): ? ''' ? 調用新浪微博Open Api實現通過命令行寫博文,功能有待完善 ? author: socrates ? date:2012-02-06 ? 新浪微博:@沒耳朵的羊 ? ''' ? sina_weibo_config = ConfigParser.ConfigParser() ? #讀取appkey相關配置文件 ? try: ? ? ? sina_weibo_config.readfp(open('sina_weibo_config.ini')) ? except ConfigParser.Error: ? ? ? print 'read sina_weibo_config.ini failed.' ?? ? #獲取需要的信息 ? consumer_key = sina_weibo_config.get("userinfo","CONSUMER_KEY") ? consumer_secret =sina_weibo_config.get("userinfo","CONSUMER_SECRET") ? token = sina_weibo_config.get("userinfo","TOKEN") ? token_sercet = sina_weibo_config.get("userinfo","TOKEN_SECRET") ? #調用新浪微博OpenApi(python版) ? auth = OAuthHandler(consumer_key, consumer_secret) ? auth.setToken(token, token_sercet) ? api = API(auth) ? return api; ? #通過命令行輸入要發布的內容 # ? ?weibo_content = raw_input('Please input content:') # ? ?status = api.update_status(status=weibo_content) # ? ?print "Press sina weibo successful, content is: %s" % status.text # ? ?iNum = 0 # ? ?while True: # ? ? ? ?#上傳圖片,名稱和內容如果重復,open api會檢查,內容采用了取當前時間的機制 # ? ? ? ?#圖片名稱從0-5循環遍歷 # ? ? ? ?status = api.upload(str(iNum)+ '.jpg', time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) # ? ? ? ?time.sleep(SLEEP_TIME_LONG) # ? ? # ? ? ? ?if iNum == MAX_PIC_NUM: # ? ? ? ? ? ?iNum = 0 # ? ? ? ?else: # ? ? ? ? ? ?iNum += 1 def get_friends(api, user_id): ? ? ''' ? Function:獲取關注的用戶列表 ? Input:api ? ? ? ? ?user_id:指定用戶的ID ? Output: NONE ? author: socrates ? blog:http://blog.csdn.net/dyx1024 ? date:2012-04-14 ? ''' ?? ? print 'friends list: ' ? total_friends = 0 ? next_cursor = -1 ? while next_cursor != 0: ? ? ? timeline = api.friends(user_id,'','','',next_cursor) ? ? ? if isinstance(timeline, tuple): ? ? ? ? ? ? ? next_cursor = timeline[1] ? ? ? ? ? ? ? total_friends += len(timeline[0]) ? ? ? ? ? ? ? for line in timeline[0]: ? ? ? ? ? ? ? ? ? fid = line.__getattribute__("id") ? ? ? ? ? ? ? ? ? name = line.__getattribute__("screen_name") ? ? ? ? ? ? ? ? ? text = "friends---"+ str(fid) +":"+ name ? ? ? ? ? ? ? ? ? text = text.encode("gbk") ? ? ? ? ? ? ? ? ? print text ? ? ? else: ? ? ? ? ? next_cursor = 0 ? ? ? ? ? total_friends += len(timeline) ? ? ? ? ? for line in timeline: ? ? ? ? ? ? ? fid = line.__getattribute__("id") ? ? ? ? ? ? ? name = line.__getattribute__("screen_name") ? ? ? ? ? ? ? text = "friends---"+ str(fid) +":"+ name ? ? ? ? ? ? ? text = text.encode("gbk") ? ? ? ? ? ? ? print text ? ? ? ? ? ? ?? ? print 'Total friends: %d' % total_friends ? ? ? ? ? def get_followers(api, user_id): ? ? ''' ? Function:獲取用戶的粉絲 ? Input:api ? ? ? ? ?user_id:指定用戶的ID ? Output: NONE ? author: socrates ? blog:http://blog.csdn.net/dyx1024 ? date:2012-04-14 ? ''' ?? ? print 'followers list: ' ? total_friends = 0 ? next_cursor = -1 ? while next_cursor != 0: ? ? ? timeline = api.followers(user_id,'','','',next_cursor) ? ? ? if isinstance(timeline, tuple): ? ? ? ? ? ? ? next_cursor = timeline[1] ? ? ? ? ? ? ? total_friends += len(timeline[0]) ? ? ? ? ? ? ? for line in timeline[0]: ? ? ? ? ? ? ? ? ? fid = line.__getattribute__("id") ? ? ? ? ? ? ? ? ? name = line.__getattribute__("screen_name") ? ? ? ? ? ? ? ? ? text = "followers---"+ str(fid) +":"+ name ? ? ? ? ? ? ? ? ? text = text.encode("gbk") ? ? ? ? ? ? ? ? ? print text ? ? ? else: ? ? ? ? ? next_cursor = 0 ? ? ? ? ? total_friends += len(timeline) ? ? ? ? ? for line in timeline: ? ? ? ? ? ? ? fid = line.__getattribute__("id") ? ? ? ? ? ? ? name = line.__getattribute__("screen_name") ? ? ? ? ? ? ? text = "followers---"+ str(fid) +":"+ name ? ? ? ? ? ? ? text = text.encode("gbk") ? ? ? ? ? ? ? print text ? ? ? ? ? ? ?? ? print 'Total followers: %d' % total_friends ? ? ? def main(): ? #獲取關注列表 ? get_friends(press_sina_weibo(), 2601091753) ? ?? ? #獲取粉絲 ? get_followers(press_sina_weibo(), 2601091753) ? ?? ? ? ? ? ? ? ? ? ? ? if __name__ == '__main__': ? main() ~~~ 測試: ~~~ friends list:? friends---1248584111:曹筱燊V friends---1951657750:輕博客 friends---2264489285:Qing官方活動 friends---1650867513:365day friends---1296492473:單車旅行的肥貓 friends---1678325381:看得見風景的記憶 friends---2129867007:國家地理攝影 friends---2179565352:地球人Echo friends---2447164602:小克愛家居 friends---1742924093:60designwebpick friends---2261697941:輕家居 friends---1072112375:cugala friends---1917369903:閆璐 friends---2485697323:鏡頭中的黑白世界 friends---1400314314:源形畢露 friends---1629756430:LoveLomo friends---2638745273:小賢d點滴 friends---1401880315:左耳朵耗子 friends---1993292930:經典經濟學 friends---2557129567:華為中國區 friends---1671248621:林正剛 friends---1670481425:伯樂在線官方微博 friends---1216265283:修羅陛下的微博 friends---2694391504:口袋英語2012 friends---1924010407:laiyonghao friends---1784501333:數據挖掘與數據分析 friends---2340488972:BalaBala_Fiona friends---1097438111:小洋洋的西紅柿醬 friends---1649005320:俞敏洪 friends---2640459400:讀書的旅程 friends---1879347450:西安生活情報 friends---1949305184:微博桌面 friends---1894238970:developerWorks friends---1400220917:開源中國 friends---2093492691:程序員的那些事 friends---1746173800:InfoQ friends---2140710271:芝雪兒 friends---1100856704:余承東 friends---1839167003:華為終端官方微博 friends---1975995305:西安晚報 friends---2202941172:陜西美食 friends---1717833412:華商報 friends---1750354524:西安交通旅游廣播 friends---1698784044:三秦都市報 friends---1642909335:微博小秘書 friends---1784599353:davewliu friends---1801473501:徐沛欣 friends---1806762625:陳一舟 friends---1798056081:萬網張向東 friends---1839240561:魯明同學 friends---1756644751:孫陶然 friends---1497145741:楊楊楊楊楊楊楊 friends---1777984105:王微 friends---1749127163:雷軍 friends---1657288682:葉朋 friends---1764529885:唐彬 friends---1861284644:盧琪隆 friends---1781681447:求伯君 friends---1055071394:姚玨 friends---1255647187:丁守謙 friends---1662521105:PPS徐偉峰 friends---1699907747:ChinaCache王松 friends---1744303552:謝國睿 friends---1657681711:潛水員莊辰超 friends---1812591014:徐少春 friends---1759084801:暴風馮鑫 friends---1772406523:買彥州 friends---1822223433:宮玉國 friends---1768340073:沈博陽 friends---1831348402:billgates friends---1670071920:史玉柱 Total friends: 71 followers list:? followers---2463471483:吃貨通 followers---1097438111:小洋洋的西紅柿醬 followers---1659617193:在少有人走的路上 followers---2386093060:朵朵奇6850 followers---2340488972:BalaBala_Fiona followers---2090442510:寧兒_YOYO followers---2215084900:景濤濤 followers---2140710271:芝雪兒 Total followers: 8 ~~~ 可見,與實際數目相等,列表獲取完整,由于我的粉絲太少了![委屈](https://box.kancloud.cn/2016-01-25_56a5a367bba9a.gif) ,測試不出翻頁的效果,測試了下別人的,顯示正常。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看