gpt4 book ai didi

python - 通过域名将网络流量与授权列表进行比较

转载 作者:太空宇宙 更新时间:2023-11-03 20:20:26 25 4
gpt4 key购买 nike

我正在尝试解析网络流量并将流量中的域名与最常见网站的列表进行比较。目的是打印不在常见网站列表中的所有网站名称


with open('/Users/downloads/scripting_for_security/resources/top_100.txt') as f:
safeAdd = f.readlines(),


with open('/Users/downloads/scripting_for_security/resources/traffic_log.txt') as n:
netTraffic = n.readlines(),

domainTraffic = re.findall(r'\s(?:www.)?(\w+.com)', netTraffic)


for i in safeAdd:
for e in domainTraffic:
if i != e:
print(e)

出现类型错误

TypeError Traceback (most recent call last) in 8 netTraffic = n.readlines(), 9 ---> 10 domainTraffic = re.findall(r'\s(?:www.)?(\w+.com)', netTraffic) 11 12

~/anaconda3/lib/python3.7/re.py in findall(pattern, string, flags) 221 222 Empty matches are included in the result.""" --> 223 return _compile(pattern, flags).findall(string) 224 225 def finditer(pattern, string, flags=0):

TypeError: expected string or bytes-like object

最佳答案

netTraffic 是一个列表,按照https://docs.python.org/3/tutorial/inputoutput.html

findall 需要字符串类型的第二个参数 https://docs.python.org/3/library/re.html#re.findall

关于python - 通过域名将网络流量与授权列表进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58193414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com