在使用了漂亮汤的soup.findAll('a', {'link': 'go to'})之后,我提取了一个链接列表,如:
lis_links = ['https://foo.com/019774_s009_TEV 234.xml https://foo.com/019774_s009_TEV 23.xml https://foo.com/019774_s009_TEV24.xml https://foo.com/019774_s009_TEV 120.xml https://foo.com/WERW FOR INJ.xml']如您所见,有些链接有"",如何用它的正确编码来修复空格(我猜它的是我试着使用replace(' ', '%20'),但是我无法控制在哪里使用它。
发布于 2017-04-15 16:26:20
使用负前瞻查找所有未后面跟着http:\s(?!http)的空格
Python示例
import re
def fixLinks(str):
   return re.sub(r"\s(?!http)", "%20", str)
links = ["https://foo.com/019774_s009_TEV 234.xml https://foo.com/019774_s009_TEV 23.xml https://foo.com/019774_s009_TEV24.xml https://foo.com/019774_s009_TEV 120.xml https://foo.com/WERW FOR INJ.xml"]
links[0] = fixLinks(links[0])
print links[0];https://stackoverflow.com/questions/43428125
复制相似问题