目錄
一、目標(biāo)1:GET數(shù)據(jù)包的處理
1、GET數(shù)據(jù)包中參數(shù)的提取
2、GET請(qǐng)求中 統(tǒng)計(jì)參數(shù)個(gè)數(shù)
二、目標(biāo)2:POST數(shù)據(jù)包的處理
1、post中參數(shù)個(gè)數(shù)的提取
2、POST請(qǐng)求中 統(tǒng)計(jì)參數(shù)個(gè)數(shù)文章來源:http://www.zghlxwxcb.cn/news/detail-695135.html
一、目標(biāo)1:GET數(shù)據(jù)包的處理
1、GET數(shù)據(jù)包中參數(shù)的提取
import re
def extract_get_parameters(request):
# 查找GET請(qǐng)求中的參數(shù)部分
match = re.search(r'GET\s+/.*\?(.*)\s+HTTP', request)
if match:
parameters = match.group(1)
# 將參數(shù)部分按照 '&' 分割成鍵值對(duì)
parameter_list = parameters.split('&')
# 將鍵值對(duì)解析為字典形式
parameters_dict = {}
for parameter in parameter_list:
key, value = parameter.split('=')
parameters_dict[key] = value
return parameters_dict
return {}
# 示例請(qǐng)求
request = "GET /xxxx/xxxx HTTP/1.1\nHost: x.x.x.x.cn\n……{此處省略一萬(wàn)字}"
parameters = extract_get_parameters(request)
print(parameters)
2、GET請(qǐng)求中 統(tǒng)計(jì)參數(shù)個(gè)數(shù)
import re
def count_get_parameters(request):
# 查找GET請(qǐng)求中的參數(shù)部分
match = re.search(r'GET\s+/.*\?(.*)\s+HTTP', request)
if match:
parameters = match.group(1)
# 將參數(shù)部分按照 '&' 分割成鍵值對(duì)
parameter_list = parameters.split('&')
# 統(tǒng)計(jì)參數(shù)個(gè)數(shù)
return len(parameter_list)
return 0
# 示例請(qǐng)求
request = "GET /xxxx/xxxx HTTP/1.1\nHost: x.x.x.x.cn\n……{此處省略一萬(wàn)字}"
count = count_get_parameters(request)
print(count)
二、目標(biāo)2:POST數(shù)據(jù)包的處理
1、post中參數(shù)個(gè)數(shù)的提取
import re
def count_post_parameters(post_data):
# 使用正則表達(dá)式提取JSON數(shù)據(jù)
pattern = r"\{.*\}"
match = re.search(pattern, post_data)
if match:
json_data = match.group()
parsed_data = json.loads(json_data)
parameter_count = len(parsed_data)
return parameter_count
else:
return 0
# 示例用法
post_data = '''POST /xxxx/xxxx HTTP/1.1\nHost: x.x.x.x.cn\n……{此處省略一萬(wàn)字}'''
parameter_count = count_post_parameters(post_data)
print(parameter_count) # 輸出:4
2、POST請(qǐng)求中 統(tǒng)計(jì)參數(shù)個(gè)數(shù)
(與GET類似,就不再做敘述了)文章來源地址http://www.zghlxwxcb.cn/news/detail-695135.html
到了這里,關(guān)于【網(wǎng)絡(luò)安全帶你練爬蟲-100練】第22練:數(shù)據(jù)包中參數(shù)提取與處理的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!