遍历多个 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("\n"),
    'Referer':load_config('referers.txt')[random.randint(0,len(load_config('referers.txt'))-1)].strip("\n"),
    'Accept':load_config('acceptall.txt')[random.randint(0,len(load_config('acceptall.txt'))-1)].strip("\n"),
}
print(headers)

2020-04-25  00:52:04

猜你喜欢

转载自www.cnblogs.com/hany-postq473111315/p/12771248.html
今日推荐