列1:
"""
s2 = "http://www.interoem.com/messageinfo.asp?id=35`
http://3995503.com/class/class09/news_show.asp?id=14
http://lib.wzmc.edu.cn/news/onews.asp?id=769
http://www.zy-ls.com/alfx.asp?newsid=377&id=6
http://www.fincm.com/newslist.asp?id=415"
"""
import re
s2 = """http://www.interoem.com/messageinfo.asp?id=35`
http://3995503.com/class/class09/news_show.asp?id=14
http://lib.wzmc.edu.cn/news/onews.asp?id=769
http://www.zy-ls.com/alfx.asp?newsid=377&id=6
http://www.fincm.com/newslist.asp?id=415"""
#小白型代码
ret = re.findall(r"http://.*?\.asp",s2)
print(ret)
str = s2.split("?")
list1 = list()
list1.append(str[0])
del str[0]
del str[len(str)-1]
for i in str:
j = i.split("\n")
list1.append(j[1])
print(list1)
#大牛型代码
p = r"(http://.*?/).*"
print(re.sub(p, lambda x: x.group(1),s2))
方法1:
简单的字符串进行处理,使用两次split,切割出来的列表,然后进行对列表处理。
字符串的处理是工作中常创建的操作想知道更多请关注
方法2:
使用分组提取主要信息,group(1)就是 要提取出来的网址
使用匿名函数经行处理的到处理后的数据 直接得到数据