<span class="comment-info"> <a class="" href="https://www.douban.com/people/duduxiongzhifu/">嘟嘟熊之父</a> <span>看过</span> <span class="allstar20 rating" title="较差"></span> <span class="comment-time" title="2023-06-02 14:46:24"> 2023-06-02 14:46:24 </span> <span class="comment-location">北京</span>如何提取其中的时间信息
时间: 2023-10-17 07:05:12 浏览: 46
可以使用正则表达式来提取时间信息。示例代码如下:
```python
import re
text = '<span class="comment-info"> <a class="" href="https://www.douban.com/people/duduxiongzhifu/">嘟嘟熊之父</a> <span>看过</span> <span class="allstar20 rating" title="较差"></span> <span class="comment-time" title="2023-06-02 14:46:24"> 2023-06-02 14:46:24 </span> <span class="comment-location">北京</span>'
pattern = r'<span class="comment-time" title="([\d-:\s]+)">'
match = re.search(pattern, text)
if match:
time_info = match.group(1)
print(time_info.strip())
```
输出结果为:`2023-06-02 14:46:24`。
这段代码使用正则表达式`r'<span class="comment-time" title="([\d-:\s]+)">'`匹配`<span>`标签的`title`属性中的时间信息。`([\d-:\s]+)`表示匹配一个或多个数字、连字符`-`、冒号`:`和空格字符`\s`的组合。`re.search()`函数在文本中搜索第一个匹配的模式,并返回一个包含匹配信息的`Match`对象。通过`Match`对象的`group(1)`方法获取第一个捕获组的字符串。最后使用`strip()`方法去除多余的空格字符。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<html> <head> <meta charset="utf-8" /> <title>星星国际影城</title> <script src="js/main.js" type="text/javascript"></script> </head> <body> 登录| 注册| 全国服务热线:888-8888888 < img src="images/logo.jpg" title="" alt="logo" /> 首页 影片 影城 购票 影城活动 会员服务 顾客互动 <input type="text" placeholder="搜索影片" name="search"/> <input type="button" name="btn" value="" /> < img src="images/b1.png" /> < img src="images/b2.png" /> < img src="images/b3.png" /> 在每行代码进行解释
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<template> <el-row class="header"> <el-col :span="24"> 后台管理系统 注销 </el-col> </el-row> <el-row class="content"> <el-col :span="6" class="sidebar"> <el-menu :default-active="activeMenu" class="menu"> <el-menu-item index="1"> 首页 </el-menu-item> <el-menu-item index="/category"> 分类管理 <router-link to="/category"> <el-menu-item>分类管理</el-menu-item> </router-link> </el-menu-item> <el-menu-item index="3"> 系统设置 </el-menu-item> </el-menu> </el-col> <el-col :span="18" class="main"> <router-view ></router-view> </el-col> </el-row> <el-row class="footer"> <el-col :span="24"> 版权所有 © 2022 后台管理系统 </el-col> </el-row> </template>还是会跳到新页面
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
Response was of unexpected text/html ContentType. Incoming portion of HTML stream: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>CXF - Service list</title></head><body>Available SOAP services:
IBgsOutServicedeclarationqureyStatusqureyDecldeclarationBgsoutDocument Endpoint address: http://sz.91etg.com:9310/etgwebservice/iBgsOut
WSDL : {http://impl.service.bgsOut.winlu.com/}BgsOutServiceImplService
Target namespace
WSDL : {http://impl.service.bgsOut.winlu.com/}BgsOutServiceImplService
Target namespace