python 循环替换问题求助?
循环替换图片地址遇到问题:
代码如下:
结果:
怎么样才能得到这样的结果:
代码如下:
#! /usr/bin/env python
# coding:utf-8
import MySQLdb
raw_img = ['http://p3.pstatp.com/large/242d000048b8442a96d0','http://p3.pstatp.com/large/242d000048b8442a96d1']
new_img = ['0.png','1.png']
article_main = '<img alt="朋友圈现“神药”可控孩子性别,专家:呵呵!" img_height="340" img_width="600" inline="0" src="http://p3.pstatp.com/large/242d000048b8442a96d1"/><img alt="朋友圈现“神药”可控孩子性别,专家:呵呵!" img_height="340" img_width="600" inline="0" src="http://p3.pstatp.com/large/242d000048b8442a96d0"/>'
k = 0
for i in raw_img:
new_article_main = article_main.replace(i,new_img[k]).replace(i,new_img[k])
k += 1
print new_article_main
exit()
结果:
<img alt="朋友圈现“神药”可控孩子性别,专家:呵呵!" img_height="340" img_width="600" inline="0" src="1.png"/><img alt="朋友圈现“神药”可控孩子性别,专家:呵呵!" img_height="340" img_width="600" inline="0" src="http://p3.pstatp.com/large/242d000048b8442a96d0"/>
怎么样才能得到这样的结果:
<img alt="朋友圈现“神药”可控孩子性别,专家:呵呵!" img_height="340" img_width="600" inline="0" src="1.png"/><img alt="朋友圈现“神药”可控孩子性别,专家:呵呵!" img_height="340" img_width="600" inline="0" src="0.png"/>
1 个回复
哚颜三卫
赞同来自: