日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python3通过request多进程获取驾校一点通试题库

發布時間:2024/1/8 python 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3通过request多进程获取驾校一点通试题库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 通過開發者工具找到試題鏈接地址;
  • 對試題鏈接的url進行分析,發現index是試題id名稱,構造隨機數,可使用range或者excel拉出全部;
  • 對json數據進行字段分析
  • 我這里分開寫了兩個腳本,一個是獲取數據一個是轉成excel,本文主要為多進程獲取數據
  • 開發環境python3.9.1/windows10/vscode
  • #coding:utf-8 import requests from concurrent.futures import ProcessPoolExecutor import json# 通過url獲取數據 # url = 'http://mnks.jxedt.com/get_question?r=0.5376675619396274&index=3' urls_list = [] with open('D:/YYFX/ip.txt','r') as f:for line in f:#print line,urls_list.append(line.replace('\n', '')) #模擬瀏覽器header hea = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'} #進程 pool = ProcessPoolExecutor(20) def get_page(url):#requests.get 自帶 json.loadresponse = requests.get('http://%s'%(url),headers = hea,timeout = 30 ,verify=False)response = response.content#將bytes轉換成字符串response = response.decode('utf-8')return responsedef read_data(future,*args,**kwargs):response = future.result()state = json.loads(response) # print(response.status_code,response.url)print (state)#product = response1["question"]+'\n'with open('%s.json'%'data','a',encoding='utf-8') as f: #保存json數據防止亂碼f.write(json.dumps(state,ensure_ascii=False) + '\n')f.close()def main():for url in urls_list:done = pool.submit(get_page,url)done.add_done_callback(read_data) if __name__ == '__main__':main()pool.shutdown(wait=True)f.close()

    ?

  • 總結

    以上是生活随笔為你收集整理的python3通过request多进程获取驾校一点通试题库的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。