最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python案例練習(xí)合集

 更新時間:2022年02月10日 09:59:04   作者:阿南-ana  
這篇文章主要介紹了python案例學(xué)習(xí)合集,主要的分享對的練習(xí)案例有python批量查詢、python批量請求(GET?|?POST)、python列表轉(zhuǎn)集合練習(xí),需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助

一、python批量查詢練習(xí)

通過接口批量查詢該ip是否屬于指定接口:

import requests
import json

if __name__ == "__main__":
? ? ? ? headers = {
? ? ? ? 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36'
? ? }
? ? # 獲取源IP
? ? with open('./ip.txt','r') as fp:
? ? ? ?list_ip = fp.readlines()

? ? ? ?# ?處理每個ip后面對\n
? ? ? ?for li in list_ip:
? ? ? ? ? li = li.rstrip()
? ? ? ? ? url="http://www.xxxx.com/api/query_ip?ip={0}&flag=1&key=cdbcbdhbhcbdhcbhdbchdbchdbch&user=root".format(li)
? ? ? ? ? #
? ? ? ? ? result_json = requests.get(url, headers=headers)
? ? ? ? ? # print(result_json.json())
? ? ? ? ? # 獲取到數(shù)據(jù)和未獲取到數(shù)據(jù)最終打印對結(jié)果要不一樣
? ? ? ? ? if result_json.json()['total'] == 0:
? ? ? ? ? ? ? cw_url="http://www.sss.cn/api/query_ip?ip={0}&flag=1&key=fjdifjdifncjdnjcndjhfjndjnjdhfjdhj&user=root".format(li)
? ? ? ? ? ? ? cw_result_json = requests.get(cw_url,headers=headers)
? ? ? ? ? ? ? print("XXX科技CMDB未發(fā)現(xiàn)該資產(chǎn) ->",end="")
? ? ? ? ? ? ? if cw_result_json.json()['total']==0:
? ? ? ? ? ? ? ? ? print(li + " <- SSSSCMDB未發(fā)現(xiàn)該資產(chǎn)")
? ? ? ? ? ? ? ? ? print(result_json.json(),cw_result_json.json())
? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? print("該資產(chǎn)屬于SSSSCMDB:")
? ? ? ? ? ? ? ? ? ip1 = cw_result_json.json()['data'][0]['ip1']
? ? ? ? ? ? ? ? ? company = cw_result_json.json()['data'][0]['company']
? ? ? ? ? ? ? ? ? profile_center = cw_result_json.json()['data'][0]['profit_center']
? ? ? ? ? ? ? ? ? platform = cw_result_json.json()['data'][0]['platform']
? ? ? ? ? ? ? ? ? leader = cw_result_json.json()['data'][0]['leader']
? ? ? ? ? ? ? ? ? email = cw_result_json.json()['data'][0]['email']
? ? ? ? ? ? ? ? ? print(ip1 + ' ?' + company + ' ?' + profile_center + ' ?' + platform + ' ?' + leader + ' ?' + email)
? ? ? ? ? else:

? ? ? ? ? ? ? ip1 = result_json.json()['data'][0]['ip1']
? ? ? ? ? ? ? company = result_json.json()['data'][0]['company']
? ? ? ? ? ? ? profile_center = result_json.json()['data'][0]['profit_center']
? ? ? ? ? ? ? platform = result_json.json()['data'][0]['platform']
? ? ? ? ? ? ? leader = result_json.json()['data'][0]['leader']
? ? ? ? ? ? ? email = result_json.json()['data'][0]['email']
? ? ? ? ? ? ? print(ip1 + ' ?' + company + ' ?' + profile_center + ' ?' + platform + ' ?' + leader + '?

二、python批量請求(GET | POST)

本案例為普通的測試案例,主要用于測試通過get請求和post請求產(chǎn)生響應(yīng)是否一致,主要針對響應(yīng)碼為200的結(jié)果進行輸出,沒有什么技術(shù)含量!

#-*- coding:utf-8 -*-

import requests
def apiRequest():
? ? header = {
? ? ? ? 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36',
? ? ? ? 'Cookie': 'JSESSIONID=E65BD767F22CBEFE30BAF33D84A59072',
? ? ? ? 'Referer':'http://aaa.xxx.com',
? ? ? ? 'Content-Type':'application/json;'
? ? }
? ? with open('url.txt','r',encoding='utf-8') as fp:
? ? ? ? urls = fp.readlines()
? ? ? ? for li in urls:

? ? ? ? ? ? get_response = requests.get(url=li,headers=header)
? ? ? ? ? ? post_response = requests.post(url=li, headers=header)


? ? ? ? ? ? if get_response.status_code == 200 or post_response.status_code == 200:
? ? ? ? ? ? ? ? print(li.strip()+"請求測試結(jié)果如下:")
? ? ? ? ? ? ? ? print("GET請求測試結(jié)果",get_response.content)
? ? ? ? ? ? ? ? print("POST請求測試結(jié)果", post_response.content)
if __name__ == '__main__':
? ? apiRequest()

三、python列表轉(zhuǎn)集合練習(xí)

#處理字符串重復(fù)問題—本練習(xí)用于fuzz字典去重

if __name__ == '__main__':
? ? with open('E:/xilie/web/fuzzDicts-master/apiDict/api.txt','r') as fp:
? ? ? ? list1 = fp.readlines()
? ? ? ? list2 = set(list1)
? ? ? ? print("去重前的條數(shù):"+str(len(list1)))
? ? ? ? print(type(list2), "去重后的條數(shù)"+str(len(list2)))

? ? with open('E:/xilie/web/fuzzDicts-master/apiDict/new_api.txt','w+') as fp1:
? ? ? ? for li1 in list2:
? ? ? ? ? ? fp1.write(li1)
? ? ? ? print("已將去重內(nèi)容寫入新文件?。?!")

到此這篇關(guān)于python案例學(xué)習(xí)合集的文章就介紹到這了,更多相關(guān)python案例內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python 獲取圖片GPS等信息鎖定圖片拍攝地點、拍攝時間(實例代碼)

    Python 獲取圖片GPS等信息鎖定圖片拍攝地點、拍攝時間(實例代碼)

    這篇文章主要介紹了Python 獲取圖片GPS等信息鎖定圖片拍攝地點、拍攝時間,先把圖片以二進制的格式讀取出來,然后通過 exifread 庫把里面的 GPS 信息提取出來,再以特定的格式打印出來,本文通過實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • pymongo insert_many 批量插入的實例

    pymongo insert_many 批量插入的實例

    這篇文章主要介紹了pymongo insert_many 批量插入的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • 17條提高工作效率的Python技巧分享

    17條提高工作效率的Python技巧分享

    這篇文章主要介紹了17條提高工作效率的Python技巧分享,掌握這些Python技巧可以讓我們的生活更加輕松,本文就日常中經(jīng)常使用到的Python技巧進行歸納總結(jié),對于常用的17條技巧均給出了完整的代碼示例和具體講解,需要的朋友可以參考下
    2022-01-01
  • LyScript實現(xiàn)Hook改寫MessageBox的方法詳解

    LyScript實現(xiàn)Hook改寫MessageBox的方法詳解

    LyScript可實現(xiàn)自定義匯編指令的替換功能。用戶可自行編寫匯編指令,將程序中特定的通用函數(shù)進行功能改寫與轉(zhuǎn)向操作,此功能原理是簡單的Hook操作。本文將詳細(xì)介紹Hook改寫MessageBox的方法,感興趣的可以了解一下
    2022-09-09
  • python版微信跳一跳游戲輔助

    python版微信跳一跳游戲輔助

    這篇文章主要為大家詳細(xì)介紹了python版微信跳一跳游戲輔助,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • Python中*args和**kwargs的作用

    Python中*args和**kwargs的作用

    *args和**kwargs,以及單獨的*,**到底是啥作用呢?原理是啥呢?讀完這篇文章你就徹底明白了,感興趣的朋友跟隨小編一起看看吧
    2023-11-11
  • python模擬菜刀反彈shell繞過限制【推薦】

    python模擬菜刀反彈shell繞過限制【推薦】

    這篇文章主要介紹了利用python模擬菜刀反彈shell繞過限制,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06
  • Python中的多重裝飾器

    Python中的多重裝飾器

    這篇文章主要介紹了Python中的多重裝飾器,多重裝飾器即多個裝飾器修飾同一個對象,但實際上并非完全如此,本文用實例講解了各種情況,需要的朋友可以參考下
    2015-04-04
  • python實現(xiàn)楊氏矩陣查找

    python實現(xiàn)楊氏矩陣查找

    這篇文章主要為大家詳細(xì)介紹了Python實現(xiàn)楊氏矩陣查找,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • python中的取反操作符(~)

    python中的取反操作符(~)

    這篇文章主要介紹了python中的取反操作符(~),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03

最新評論

栖霞市| 嘉祥县| 龙游县| 上虞市| 台南县| 安乡县| 武隆县| 青河县| 宁河县| 乌审旗| 铜陵市| 叙永县| 丹寨县| 平塘县| 上蔡县| 青田县| 福清市| 江山市| 平泉县| 喜德县| 娄底市| 吉林市| 阿拉尔市| 阿鲁科尔沁旗| 汉中市| 韶山市| 安国市| 许昌县| 门头沟区| 勐海县| 抚远县| 乌兰县| 恩平市| 晋州市| 远安县| 同心县| 台安县| 长葛市| 长寿区| 莎车县| 根河市|