遍历多个 txt 文件进行获取值

import random


def load_config(path):
    with open(path,'r') as tou:
        return [line for line in tou.readlines()]

headers = {
    'User-Agent':load_config('useragents.txt')[random.randint(0,len(load_config('useragents.txt'))-1)].strip("
"),
    'Referer':load_config('referers.txt')[random.randint(0,len(load_config('referers.txt'))-1)].strip("
"),
    'Accept':load_config('acceptall.txt')[random.randint(0,len(load_config('acceptall.txt'))-1)].strip("
"),
}
print(headers)

2020-04-25  00:52:04

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12771248.html