网页内源代码模板如下: <body> [talkid:138031370]2014年4月20日 03:55:45 , <span class="hint-success" data-hint"">111222</span> 向 <span class="hint-success" data-hint="">232323</span> 发送 我们已经是好友了,开始聊天吧! <p> ()</p> [talkid:138031371]2014年4月20日 04:45:45 , <span class="hint-success" data-hint"">111222</span> 向 <span class="hint-success" data-hint="">123456</span> 发送 音频 :[<a href="files/f/f123fsasfsfsjdfrhf_n.m4a"]>音频</a> <p> ()</p> [talkid:138031372]2014年4月20日 04:55:45 , <span class="hint-success" data-hint"">111222</span> 向 <span class="hint-success" data-hint="">123456</span> 发送 图片 :[<a href="files/f/f123fsasfsfsjdfrhf_n.jpg"]>图片</a> <p> ()</p> [talkid:137031382]2014年4月22日 04:45:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 音频 :[<a href="files/f/f123fsasfsfsjdfrhf_n.m4a"]>音频</a> <p> ()</p> [talkid:137031383]2014年4月23日 04:55:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 图片 :[<a href="files/f/f123fsasfsfsjdfrhf_n.jpg"]>图片</a> <p> ()</p> [talkid:137031384]2014年4月24日 05:55:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 我们已经是好友了,开始聊天吧! <p> ()</p> </body> </html> 利用python爬虫,打开C:/Users/test/Desktop/DIDItest文件夹下所有文件夹内的html文件源代码,
时间: 2023-08-14 15:59:38 浏览: 123
您可以使用Python中的`os`模块和`BeautifulSoup`库来实现这个功能。下面是一个示例代码:
```python
import os
from bs4 import BeautifulSoup
folder_path = 'C:/Users/test/Desktop/DIDItest'
# 遍历文件夹
for root, dirs, files in os.walk(folder_path):
for file_name in files:
if file_name.endswith('.html'):
file_path = os.path.join(root, file_name)
# 打开文件并读取源代码
with open(file_path, 'r', encoding='utf-8') as file:
source_code = file.read()
# 使用BeautifulSoup解析源代码
soup = BeautifulSoup(source_code, 'html.parser')
# 进行相关操作,例如提取特定标签或数据
# 这里只是简单地打印源代码
print(soup.prettify())
```
您可以根据自己的需求修改代码来处理源代码,例如提取特定标签的内容或者执行其他操作。请确保已经安装了`BeautifulSoup`库(可以使用`pip install beautifulsoup4`进行安装)。
阅读全文
相关推荐




网页内源代码模板如下: <body> [talkid:138031370]2014年4月20日 03:55:45 , 111222 向 232323 发送 我们已经是好友了,开始聊天吧! () [talkid:138031371]2014年4月20日 04:45:45 , 111222 向 123456 发送 音频 :[音频 () [talkid:138031372]2014年4月20日 04:55:45 , 111222 向 123456 发送 图片 :[图片 () [talkid:137031382]2014年4月22日 04:45:45 , 2323234 在群 20011 中发言 音频 :[音频 () [talkid:137031383]2014年4月23日 04:55:45 , 2323234 在群 20011 中发言 图片 :[图片 () [talkid:137031384]2014年4月24日 05:55:45 , 2323234 在群 20011 中发言 我们已经是好友了,开始聊天吧! () </body> </html> 利用python爬虫,打开C:/Users/test/Desktop/DIDItest文件夹下所有文件夹内的html文件源代码,并提取每一行<body>之间的数据,剔除 ()

网页内源代码模板如下: <html> <meta http-equiv="Content=-Type" content="text/html; charset=utf-8"> <head> </head> <body>[talkid:138031370]2014年4月20日 03:55:45 , 111222 向 232323 发送 我们已经是好友了,开始聊天吧! () [talkid:138031371]2014年4月20日 04:45:45 , 111222 向 123456 发送 音频 :[<ahref="files/f/f123fsasfsfsjdfrhf_n.m4a"]>音频
() [talkid:138031372]2014年4月20日 04:55:45 , 111222 向 123456 发送 图片 :[<ahref="files/f/f123fsasfsfsjdfrhf_n.jpg"]>图片 () </body> </html> 利用python爬虫,打开C:/Users/test/Desktop/DIDItest文件夹下多个文件夹内的html文件源代码,并爬取源代码中的ID、时间、发送号码、接收号码、发送内容,如果发送内容不为文本,则提取文件所在链接地址,并将爬取的内容写入csv中
网页内源代码模板如下: <html> <meta http-equiv="Content=-Type" content="text/html; charset=utf-8"> <head> </head> <body>[talkid:138031361]2014年4月20日 03:55:45 , 434343 向 232323 发送 我们已经是好友了,开始聊天吧! () [talkid:138031362]2014年4月20日 04:45:45 , 434343 向 123456 发送 音频 :[<ahref="files/f/f123fsasfsfsjdfrhf_n.m4a"]>音频
() [talkid:138031363]2014年4月20日 04:55:45 , 434343 向 123456 发送 音频 :[<ahref="files/f/f123fsasfsfsjdfrhf_n.jpg"]>图片 () [talkid:138031364]2014年4月20日 05:55:45 , 434343 向 3234221 发送 我们已经是好友了,开始聊天吧! () [talkid:138031365]2014年4月20日 06:55:45 , 434343 向 1359075 发送 我们已经是好友了,开始聊天吧! () </body> </html> 利用python爬虫,打开C:/Users/test/Desktop/DIDItest文件夹下多个文件夹内的html文件源代码,并爬取源代码中的ID、时间、发送号码、接收号码、发送内容,如果发送内容为音频则提取音频所在位置,反之则保留发送内容,并将爬取的内容写入csv中
网页内源代码模板如下: <html> <meta http-equiv="Content=-Type" content="text/html; charset=utf-8"> <head> </head> <body> [talkid:138031379]2014年4月20日 06:55:45 , 111222 向 342112 发送 我们已经是好友了,开始聊天吧! [talkid:137031381]2014年4月20日 03:55:45 , 2323234 在群 20011 中发言 我们已经是好友了,开始聊天吧! [talkid:137031382]2014年4月22日 04:45:45 , 2323234 在群 20011 中发言 音频 :[音频 [talkid:137031383]2014年4月23日 04:55:45 , 2323234 在群 20011 中发言 图片 :[图片 [talkid:138031387]2014年4月20日 04:45:45 , 2323234 向 543521 发送 音频 :[音频 </body> </html> 利用python爬虫,提取消息发送内容、文件名称,发送内容提取‘ 发送’后或中发言后的内容,如果有[<a href则设置为默认空值,文件名称则提取如果有[<a href则提取文件所在位置,反之则填写默认空值





