所以我有一个CSV文档,每行有元数据、XPATH和Regex字符串。脚本使用xpath来迭代API请求,然后我想使用存储在CSV中的regex和该xpath来搜索API结果中的内容。我的问题是如何使用CSV行中的数据作为文本regex搜索字符串,比如r'^\w{2}.+'
与要搜索的字符串。你知道吗
with open(rules, 'r+') as rulefile:
rreader = csv.DictReader(rulefile)
for row in rreader:
for ip, apikey in keydict.iteritems():
rulequery = {'type': 'config', 'action': 'get', 'key': apikey, 'xpath': row["xpath"]}
rrule = requests.get('https://' + ip + '/api', params = rulequery, verify=False)
rrex = re.compile('{}'.format(row["regex"]), re.MULTILINE)
for line in rrule.text:
config = rrex.findall(line)
print(config)
所以我想我可能已经找到了一个解决办法,虽然我不确定这是最好的。。。如果有人有更好的方法,可以寻求帮助。你知道吗
相关问题 更多 >
编程相关推荐