<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 1. 分析請求 分析網址:[https://m.weibo.cn/u/2145291155](https://m.weibo.cn/u/2145291155) ### ![](/assets/6.3-1.png) ### 2. 分析響應 鏈接:[https://m.weibo.cn/api/container/getIndex?type=uid&value=2145291155&containerid=1076032145291155](https://m.weibo.cn/api/container/getIndex?type=uid&value=2145291155&containerid=1076032145291155) ![](/assets/6.3-2.png) 下一條鏈接:[https://m.weibo.cn/api/container/getIndex?type=uid&value=2145291155&containerid=1076032145291155&page=2](https://m.weibo.cn/api/container/getIndex?type=uid&value=2145291155&containerid=1076032145291155&page=2) 可以后面多了一個page=2的參數 根據后面的鏈接可以發現page就是頁數,value參數值是用戶id,containerid參數值是1076032+用戶id ### 3. 實戰演練 {#3-實戰演練} ``` from urllib.parse import urlencode import requests from pyquery import PyQuery as pq from pymongo import MongoClient headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Referer': 'https://germey.gitbooks.io/python3webspider/content/6.3-Ajax%E7%BB%93%E6%9E%9C%E6%8F%90%E5%8F%96.html', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest', } client = MongoClient() db = client.weibo collection = db.weio max_page = 10 base_url = "https://m.weibo.cn/api/container/getIndex?" def get_page(page=0): params = { 'type':'uid', 'value':'2145291155', 'containerid':'1076032145291155', 'page':page, } url = base_url + urlencode(params) # print(url) try: response = requests.get(url,headers=headers) if response.status_code == 200: return response.json() except requests.ConnectionError as e: print(e.args) def parse_page(response): print(response) if response: items = response.get("data").get("cards") print(items) if items: for item in items: item = item.get("mblog") weibo = {} weibo.setdefault("id",item.get("id")) weibo.setdefault("text",item.get("text")) weibo.setdefault("attitudes",item.get("attitudes_count")) weibo.setdefault("comments",item.get("comments_count")) weibo.setdefault("reposts",item.get("reposts_count")) yield weibo def save_to_mongo(result): if collection.insert(result): print("Save to Mongo") if __name__ == "__main__": for page in range(1,max_page+1): response = get_page(page) results = parse_page(response) for result in results: print(result) save_to_mongo(result) ```
                  <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>

                              哎呀哎呀视频在线观看