我的代码是
def check(i):
data = [('ip', i),]
g=requests.post('http://www.ipvoid.com/ip-blacklist-check/', headers=headers, cookies=cookies, data=data)
string1 = unicodedata.normalize('NFKD', g.text).encode('ascii', 'ignore').decode('ascii')
r = string1.translate(str.maketrans("\n\t\r", " "))
print(str(i)+str(re.findall(r'BLACKLISTED \d+\/\d+',str(r))))
with open(sys.argv[1]) as f:
lines = f.readlines()
from multiprocessing import Pool
if __name__ == '__main__':
p = Pool(10)
p.map(check, lines)
我正在以这种形式获得结果...
212.7.219.223
['BLACKLISTED 3/96']
212.7.217.119
['BLACKLISTED 5/96']
212.7.219.226
['BLACKLISTED 4/96']
我应该添加或删除哪些内容以获得这种形式...
212.7.219.223['BLACKLISTED 3/96']
212.7.217.119['BLACKLISTED 5/96']
212.7.219.226['BLACKLISTED 4/96']
答案 0 :(得分:0)
file.readlines()
返回的行包含换行符,因此,如果您不希望使用换行符输出IP地址,则应删除它们。
更改:
lines = f.readlines()
收件人:
lines = [l.strip() for l in f]
答案 1 :(得分:0)
我同意@blhsing,尽管您可以将p.map(check, lines)
更改为
p.map(check, lines.strip())