最近chatgpt非?;?,通過chatgpt可以做很多事情,筆者也通過實際使用解決了自己的問題,都基本不用自己編程。
本文主要需要解決:
通過burpsuite批量獲取的json文件,需要處理成mysql數(shù)據(jù)庫識別的格式,方便入庫。
(1)重命名所有文件為txt后綴文件
(2)刪除txt文件無用的前N行數(shù)據(jù),其實就是頭文件數(shù)據(jù),有幾行就定義幾行。
(3)重命名txt文件為json文件。
(4)對json文件自動識別表列名,并處理數(shù)據(jù)到一個文件中。
1.chatgpt嘗試
通過fofa.info搜索"loading-wrap" && "balls" && "chat" && is_domain=true,搜索的記錄就是提供chatgpt的網(wǎng)站地址。
2.逐個網(wǎng)站測試是否可以免費使用
打開搜索中的記錄,逐個查看,有的需要輸入密碼才能方法,尋找一些免費的chatgpt。
對一些需要輸入驗證的直接pass掉,然后尋找一些不需要密碼就能訪問的。例如https://chat.77yun.cc/#/chat/1002
3.進行實際測試
可以在chatgpt中將自己的問題提出來,輸入回車后即可獲取相應的解決方法。同時對實際數(shù)據(jù)進行測試,不斷的訓練,最后達到自己想要的結果。
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:
#將所有擴展名不是.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'
#對于每個txt文件,刪除前9行的內容并保存到新的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文件,并讀取其內容
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ù),并按照列名的順序寫入數(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.總結
使用chatgpt編程非常簡單,關鍵你需要定義好你需要的東西。例如我的功能描述如下:
(1)使用python代碼實現(xiàn)以下功能:當前數(shù)據(jù)目錄為all
(2)原始代碼中首先對所有文件重命名為文件ren *.* *.txt
(3)獲取指定目錄下所有的文件,并遍歷每個文件。
(4)將所有擴展名不是 .txt 的文件重命名為同名的 .txt 文件,保證后續(xù)處理只考慮 txt 文件。
(5)對于每個txt文件,讀取文件內容并刪除前9行的內容,這一部分數(shù)據(jù)在原代碼中被稱為“頭部內容”,然后將剩余內容保存到新的txt文件中。
(6)將新的txt文件重命名為同名 .json 文件,并讀取其內容。
(7)整理 json 文件中的數(shù)據(jù),并按照列名的順序寫入數(shù)據(jù)文件out.txt中。
需要清晰的定義好想要的功能點,然后通過不停的訓練測試最終達到自己想要的效果。總之有了chatgpt后,你有產品的思路就可以,很多功能可以簡化,有編程功底的人可以更好的利用。