给我一个正则获取下面url的图片名称包括后缀, “https://tiebapic.baidu.com/forum/wh%3D200%2C90%3B/sign=1b361c3339d98d1076810433110f9437/b3fb43166d224f4a154ff9dc4cf790529922d12f.jpg?tbpicau=2023-07-11-05_32c0a7061d3c6ad700ab17039ce7ffc0”
时间: 2023-12-04 16:03:33 浏览: 66
可以使用以下正则表达式来获取图片名称及后缀```python
import reurl = "https://tiebapic.baidu.com/forum/wh%3D200%2C90%3B/sign=1b361c3339d98d1076810433110f9437/b3fb43166d224f4a154ff9dc4cf790529922d12f.jpg?tbpicau=2023-07-11-05_32c0a7061d3c6ad700ab17039ce7ffc0"
# 使用正则表达式提取图片名称及后缀
pattern = r"/([^/]+\.(?:jpg|jpeg|png|gif|bmp))"
match = re.search(pattern, url)
if match:
image_name = match.group(1)
print(image_name)
else:
print("未找到图片名称")
```
输出结果为:
```
b3fb43166d224f4a154ff9dc4cf790529922d12f.jpg
```
请注意,以上示例代码使用 Python 中的正则表达式模块 `re` 进行匹配。
相关问题
js 一个 正则验证 下面三个链接 https://live.bilibili.com/9906982?a=1 https://live.bilibili.com/9?b=` https://live.bilibili.com/99?c=A
你可以使用正则表达式来验证这三个链接。以下是一个示例的正则表达式,可以用于验证这些链接是否符合要求:
```javascript
const regex = /^https:\/\/live\.bilibili\.com\/\d+\?[a-zA-Z]=\w+$/;
const link1 = "https://live.bilibili.com/9906982?a=1";
const link2 = "https://live.bilibili.com/9?b=`";
const link3 = "https://live.bilibili.com/99?c=A";
console.log(regex.test(link1)); // true
console.log(regex.test(link2)); // false
console.log(regex.test(link3)); // true
```
这个正则表达式的含义是:以`https://live.bilibili.com/`开头,后面跟着一个或多个数字,然后是`?`,再后面是一个字母(大小写不限),最后是一个或多个字母、数字或下划线。
使用正则表达式爬虫爬取所提供的网页https://www.quanjing.com/tupian/ma.html的图片并保存下来
好的,我可以帮你解决这个问题。你可以使用Python的requests和re库来实现。
首先,你需要导入所需的库:
```python
import requests
import re
```
然后,发送HTTP请求并获取网页的内容:
```python
url = "https://www.quanjing.com/tupian/ma.html"
response = requests.get(url)
html = response.text
```
接下来,使用正则表达式匹配图片链接:
```python
pattern = r'<img.+?src="(.+?\.jpg)".*?>'
image_urls = re.findall(pattern, html)
```
现在,你可以遍历这些图片链接,并将它们保存到本地:
```python
for i, image_url in enumerate(image_urls):
response = requests.get(image_url)
with open(f"image_{i+1}.jpg", "wb") as f:
f.write(response.content)
print(f"Image {i+1} saved.")
```
这样,你就可以成功爬取并保存网页中的图片了。请注意,这只是一个简单的示例,实际应用中可能需要处理异常情况和优化代码。