在这段代码中,我试图获取某个用户在群聊中发布的图像的链接:
import groupy
from groupy import Bot, Group, Member
prog_group = Group.list().first
prog_members = prog_group.members()
prog_messages = prog_group.messages()
rojer = str(prog_members[4])
rojer_messages = ['none']
rojer_pics = []
links = open('rojer_pics.txt', 'w')
print(prog_group)
for message in prog_messages:
if message.name == rojer:
rojer_messages.append(message)
if message.attachments:
links.write(str(message) + '\n')
links.close()
问题是它在链接文件中打印了整个消息:(“Rojer Doewns:这是一个特殊的+https://i.groupme.com/406x1199.png.7679b4f1ee964656bde93448ff9cee12')>”我想要做什么,是去掉不属于 URL 的字符,所以它是这样写的:
“ https://i.groupme.com/406x1199.png.7679b4f1ee964656bde93448ff9cee12 ”
python中有没有可以像这样操作字符串的方法?