最近c(diǎn)hatgpt非常火,通過(guò)chatgpt可以做很多事情,筆者也通過(guò)實(shí)際使用解決了自己的問(wèn)題,都基本不用自己編程。
本文主要需要解決:
通過(guò)burpsuite批量獲取的json文件,需要處理成mysql數(shù)據(jù)庫(kù)識(shí)別的格式,方便入庫(kù)。
(1)重命名所有文件為txt后綴文件
(2)刪除txt文件無(wú)用的前N行數(shù)據(jù),其實(shí)就是頭文件數(shù)據(jù),有幾行就定義幾行。
(3)重命名txt文件為json文件。
(4)對(duì)json文件自動(dòng)識(shí)別表列名,并處理數(shù)據(jù)到一個(gè)文件中。
1.chatgpt嘗試
通過(guò)fofa.info搜索"loading-wrap" && "balls" && "chat" && is_domain=true,搜索的記錄就是提供chatgpt的網(wǎng)站地址。
2.逐個(gè)網(wǎng)站測(cè)試是否可以免費(fèi)使用
打開(kāi)搜索中的記錄,逐個(gè)查看,有的需要輸入密碼才能方法,尋找一些免費(fèi)的chatgpt。
對(duì)一些需要輸入驗(yàn)證的直接pass掉,然后尋找一些不需要密碼就能訪問(wèn)的。例如https://chat.77yun.cc/#/chat/1002
3.進(jìn)行實(shí)際測(cè)試
可以在chatgpt中將自己的問(wèn)題提出來(lái),輸入回車后即可獲取相應(yīng)的解決方法。同時(shí)對(duì)實(shí)際數(shù)據(jù)進(jìn)行測(cè)試,不斷的訓(xùn)練,最后達(dá)到自己想要的結(jié)果。
4.最后的代碼為
import os
import json
#獲取指定目錄下所有的文件
dir = 'all'
all_files = [f for f in os.listdir(dir) if os.path.isfile(os.path.join(dir, f))]
for file in all_files:
#將所有擴(kuò)展名不是.txt的文件改名為同名.txt文件
if not file.endswith('.txt'):
os.rename(os.path.join(dir, file), os.path.join(dir, os.path.splitext(file)[0] + '.txt'))
file = os.path.splitext(file)[0] + '.txt'
#對(duì)于每個(gè)txt文件,刪除前9行的內(nèi)容并保存到新的txt文件中
with open(os.path.join(dir, file), 'r', encoding='utf-8') as txt_file:
content = txt_file.readlines()
deleted_content = '\n'.join(content[:9])
new_content = ''.join(content[9:])
with open(os.path.join(dir, file), 'w', encoding='utf-8') as txt_file:
txt_file.write(new_content)
#將新的txt文件重命名為同名.json文件,并讀取其內(nèi)容
json_file = os.path.splitext(file)[0] + '.json'
os.rename(os.path.join(dir, file), os.path.join(dir, json_file))
with open(os.path.join(dir, json_file), 'r', encoding='utf-8') as j_file:
data = json.load(j_file)
columns = list(data['page']['list'][0].keys())
rows = []
for item in data['page']['list']:
row_values = []
for column in columns:
value = str(item[column]).replace('\n','').replace(',','')
row_values.append(value)
rows.append(','.join(row_values))
#整理json文件中的數(shù)據(jù),并按照列名的順序?qū)懭霐?shù)據(jù)文件out.txt中
with open('out.txt', 'a+', encoding='utf-8') as out_file:
if out_file.tell() == 0:
out_file.write(','.join(columns) + '\n')
out_file.write('\n'.join(rows)+'\n')
print("文件{}中的數(shù)據(jù)已寫入out.txt文件中".format(json_file))
5.總結(jié)
使用chatgpt編程非常簡(jiǎn)單,關(guān)鍵你需要定義好你需要的東西。例如我的功能描述如下:
(1)使用python代碼實(shí)現(xiàn)以下功能:當(dāng)前數(shù)據(jù)目錄為all
(2)原始代碼中首先對(duì)所有文件重命名為文件ren *.* *.txt
(3)獲取指定目錄下所有的文件,并遍歷每個(gè)文件。
(4)將所有擴(kuò)展名不是 .txt 的文件重命名為同名的 .txt 文件,保證后續(xù)處理只考慮 txt 文件。
(5)對(duì)于每個(gè)txt文件,讀取文件內(nèi)容并刪除前9行的內(nèi)容,這一部分?jǐn)?shù)據(jù)在原代碼中被稱為“頭部?jī)?nèi)容”,然后將剩余內(nèi)容保存到新的txt文件中。
(6)將新的txt文件重命名為同名 .json 文件,并讀取其內(nèi)容。
(7)整理 json 文件中的數(shù)據(jù),并按照列名的順序?qū)懭霐?shù)據(jù)文件out.txt中。
需要清晰的定義好想要的功能點(diǎn),然后通過(guò)不停的訓(xùn)練測(cè)試最終達(dá)到自己想要的效果??傊辛薱hatgpt后,你有產(chǎn)品的思路就可以,很多功能可以簡(jiǎn)化,有編程功底的人可以更好的利用。