Python 只打印.jpg扩展名结尾的链接?
问题重复:Python 只打印.jpg扩展名结尾的链接?,python,python-3.x,Python,Python 3.x,问题重复: 确保酒店图像为字符串,否则将其转换为字符串并使用endswith函数 试试这个: with open("myfile.txt", "w") as fp: for item in soup.find_all('img'): hotel_image = (item['src']) if hotel_image.endswith('.jpg'): fp.writelines(hotel_
确保酒店图像为字符串,否则将其转换为字符串并使用endswith函数 试试这个:
with open("myfile.txt", "w") as fp:
for item in soup.find_all('img'):
hotel_image = (item['src'])
if hotel_image.endswith('.jpg'):
fp.writelines(hotel_image)
尝试在“find_all”方法中使用正则表达式,如中所示:
soup.find_all('img',alt=”“,src=re.compile('jpg'))
endswith('jpg')
在循环外部打开文件,循环完成后关闭。@alex这将返回true或folse我需要返回al-link