使用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 09:15:02 浏览: 118
以下是使用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": "受理成功"
}
]
```
阅读全文