有没有把下面的给定行转换成Python的想法?
sed 's+forwarding_link+'$link'+g' first.html > index2.html
with open('first.html') as infile:
data = infile.read()
data = data.replace('forwarding_link', link)
with open('index2.html', 'w') as outfile:
outfile.write(data)
这可能对有用
由于link
是一个变量,它将在Python 中保持原样
您必须读取文件first.html
,使用string.replace
替换匹配的字符串,然后将结果转储到index2.html
中。
link = 'your link here'
with open('first.html') as infile:
data = infile.read()
data = data.replace('forwarding_link', link)
with open('index2.html', 'w') as outfile:
outfile.write(data)