在python中将参数从文件添加到给定URL
我想使用给定的URL和txt文件中的一些参数生成一系列URL 例如,给定的URL是:在python中将参数从文件添加到给定URL,python,python-2.7,Python,Python 2.7,我想使用给定的URL和txt文件中的一些参数生成一系列URL 例如,给定的URL是: http://stackoverflow.com/questions/ask1 http://stackoverflow.com/questions/ask2 它们分别存储在url.xlsx文件的Sheet1中的A1和A2中 参数存储在params.txt文件中,包含以下内容: w3e 1 123456 fy 我想生成如下URL: http://stackoverflow.com/questions/ask
http://stackoverflow.com/questions/ask1
http://stackoverflow.com/questions/ask2
它们分别存储在url.xlsx文件的Sheet1中的A1和A2中
参数存储在params.txt文件中,包含以下内容:
w3e
1
123456
fy
我想生成如下URL:
http://stackoverflow.com/questions/ask1/param.x
http://stackoverflow.com/questions/ask2/param.x
这意味着我将得到2x4=8个URL
你知道怎么做吗?非常感谢 将这两个文件读入列表,然后使用将它们合并:
from itertools import product
with open('urls.txt') as urlfile:
urls = [line.strip() for line in urlfile]
以open('params.txt')作为参数文件:
参数=[line.strip()用于paramfile中的行]
for url, param in product(urls, parameters):
print url + param