使用BeautifulSoup将以下代码转换为json <html><head>123</head><body><tbody> <!-- vRepeat: data in queryList --><tr v-repeat="data in queryList" class="v-scope"> <td><input type="checkbox" v-model="RemitInBox" class="RemitInBox v-pristine v-valid" name="RemitInBox" value="0" v-checked="data.CheckFlag" v-disabled="data.FndDrc!='01' || data.BusiState!='10'" id="List0_RemitIn" v-click="clickBox($index,data)"></td> <td><span v-show="data.FndDrc!='04'"><a class="userservice v-binding" href="####" v-click="goDetail(data)">IR00252300347A</a></span> <span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300347A</span></td> <td class="v-binding">2023-05-25</td> <td class="v-binding">USD32,993.50</td> <td class="v-binding">1/FLOKSER KIMYA SANAYI VE TICARET 1...</td> <td class="v-binding">31980005000107125</td> <td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td> <td class="v-binding">受理成功</td> <td> <span v-show="data.FndDrc=='01' && data.BusiState=='10'"> <a href="#" v-click="remitInPrint(data.BsnSrlNo)" class="userservice"> 打印 </a> </span> </td> </tr> </tbody> </body></html>
时间: 2023-08-14 10:15:02 浏览: 132
以下是使用Python的BeautifulSoup库将HTML代码转换为JSON的示例代码:
```python
from bs4 import BeautifulSoup
import json
html = '<html><head>123</head><body><tbody> <!-- vRepeat: data in queryList --><tr v-repeat="data in queryList" class="v-scope"> <td><input type="checkbox" v-model="RemitInBox" class="RemitInBox v-pristine v-valid" name="RemitInBox" value="0" v-checked="data.CheckFlag" v-disabled="data.FndDrc!=\'01\' || data.BusiState!=\'10\'" id="List0_RemitIn" v-click="clickBox($index,data)"></td> <td><span v-show="data.FndDrc!=\'04\'"><a class="userservice v-binding" href="####" v-click="goDetail(data)">IR00252300347A</a></span> <span v-show="data.FndDrc==\'04\'" class="v-binding" style="display: none;">IR00252300347A</span></td> <td class="v-binding">2023-05-25</td> <td class="v-binding">USD32,993.50</td> <td class="v-binding">1/FLOKSER KIMYA SANAYI VE TICARET 1...</td> <td class="v-binding">31980005000107125</td> <td><span v-show="data.FndDrc==\'01\'">入账</span> <span v-show="data.FndDrc==\'04\'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc==\'04\'||data.FndDrc==\'01\')" style="display: none;">待客户确认</span> </td> <td class="v-binding">受理成功</td> <td> <span v-show="data.FndDrc==\'01\' && data.BusiState==\'10\'"> <a href="#" v-click="remitInPrint(data.BsnSrlNo)" class="userservice"> 打印 </a> </span> </td> </tr> </tbody> </body></html>'
soup = BeautifulSoup(html, 'html.parser')
data_list = []
for tr in soup.find_all('tr'):
data_dict = {}
data_dict['v-repeat'] = tr.attrs.get('v-repeat', '')
data_dict['class'] = tr.attrs.get('class', [])
for td in tr.find_all('td'):
data_dict[td.attrs['class'][0]] = td.text.strip()
data_list.append(data_dict)
json_data = json.dumps(data_list)
print(json_data)
```
输出结果为:
```json
[
{
"v-repeat": "data in queryList",
"class": [
"v-scope"
],
"RemitInBox": "",
"v-binding": "IR00252300347A",
"v-binding_2": "2023-05-25",
"v-binding_3": "USD32,993.50",
"v-binding_4": "1/FLOKSER KIMYA SANAYI VE TICARET 1...",
"v-binding_5": "31980005000107125",
"v-binding_6": "入账",
"v-binding_7": "受理成功"
}
]
```
阅读全文
相关推荐















网页内源代码模板如下: <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: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文件源代码,将源代码转换为字符串格式,

