我有替换功能的问题。我可以打印链接,但无法替换链接。我忘记了哪个代码?
import urllib2
import re
htmlfile = urllib2.urlopen('http://sample.html')
htmltext = htmlfile.read()
regex = "'nav_a'>(.+?)</a></li>"
pattern = re.compile(regex)
link = re.findall(pattern,htmltext)
downloadlink = link.replace("*text to replace*", "*replace with*")
print (downloadlink)