Mun*_*b K 0 python element list
我想找到在结尾的列表中的项目jpg,png或类似的图像类型.
让我们说这是我的清单:
['http://www.ragalahari.com/index.aspx', 'http://www.ragalahari.com/index.aspx', 'http://www.ragalahari.com/news.aspx', 'http://imgcdn.raagalahari.com/feb2015/photosessions/shraddha-das-in-long-black-frock/shraddha-das-in-long-black-frock1t.jpg', 'http://imgcdn.raagalahari.com/feb2015/photosessions/shraddha-das-in-long-black-frock/shraddha-das-in-long-black-frock2t.jpg', 'http://imgcdn.raagalahari.com/feb2015/photosessions/shraddha-das-in-long-black-frock/shraddha-das-in-long-black-frock3t.jpg', 'http://www.ragalahari.com/images/facebookicon.png', 'http://www.ragalahari.com/images/searchicon.png']
Run Code Online (Sandbox Code Playgroud)
我想找到以jpg或结尾的URL png.
我的代码到此为止:
href_links = []
for a in soup.find_all('a', href=True):
href = a.get('href')
href = urljoin(link1, href)
href_links.append(href)
Run Code Online (Sandbox Code Playgroud)
您可以使用列表理解和str.endswith:
images = [x for x in href_links if x.endswith(('jpg', 'png'))]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1208 次 |
| 最近记录: |