def test_3():
import re
s = r""":"<p><img data-lazyload=\"http://img30.360buyimg.com/popWareDetail/jfs/t1/91169/26/38802/211855/644b5722Fa46be2cb/9c52956a370a403a.jpg\" style=\"width: auto; height: auto; max-width: 100%;\"><img data-lazyload=\"http://img30.360buyimg.com/popWareDetail/jfs/t1/219653/21/27995/96158/644a219aFc47f6117/ca32d66d3ff91d9c.jpg\" style=\"width: auto; height: auto; max-width: 100%;\"><img data-lazyload=\"http://img30.360buyimg.com/popWareDetail/jfs/t1/138359/6/34771/159267/644a219bFb4a9a446/f770a887c8a602e3.jpg\" style=\"width: auto; height: auto; max-width: 100%;\"><img data-lazyload=\"http://img30.360buyimg.com/popWareDetail/jfs/t1/187239/31/33559/148093/644a219bF23241763/26abfa72611f7c42.jpg\" """
# 如何用正则取字符串里面的图片
desc_img = re.findall('http?://[^"]+?\.(?:jpe?g|gif|png)(?=")', s)
print(desc_img)
if __name__ == "__main__":
test_3()
结果为空
改成:
desc_img = re.findall('http?://.*?.(?:jpe?g|gif|png)', s)
jpe?g这是啥意思
s.strip() 去掉两边空格
s.rstrip() 去除右边空格
s.lstrip() 去除左边空格
.strip(‘h’)去掉两边的h
.lstrip(‘h’)去掉左边的h
.rstrip(‘h’)去掉右边的h
**注意: strip对\n,和\t都生效**
In [1]: s = ' hello '
In [2]: s
Out[2]: ' hello '
In [3]: s.strip()
Out[3]: 'hello'
In [4]: s.rstrip()
Out[4]: ' hello'
In [5]: s.lstrip()
Out[5]: 'hello '
In [6]: s = '\nhello\t\t'
Out[7]: 'hello'
In [8]: s = 'helloh'
In [9]: s.strip('h') ##去除两边的h
Out[9]: 'ello'
In [10]: s.rstrip('h') ##去除右边的h
Out[10]: 'hello'
In [11]: s.lstrip('') #去除左边的h
Out[11]: 'elloh'