alex_bn_lee

导航

[1099] Extract the text from HTML

Here's an example using Python with the BeautifulSoup library to get the text inside the <option> tags:

from bs4 import BeautifulSoup

html = '''
<option selected="selected" value="47">Approval under Control of Burning Reg</option>
<option value="51">Court Ordered Modification</option>
<option value="69">EHC Licence</option>
<option value="52">Licence Bulk Variation</option>
<option value="3">Load Reduction Agreement</option>
<option value="4">Load Reduction Agreement - Termination</option>
<option value="33">Penalty Notice</option>
<option value="72">PRCE Act - s.36 Compliance Notice</option>
<option value="74">PRCE Act - s.44 Revocation Notice</option>
<option value="73">PRCE Act - s.44 Variation Notice</option>
<option value="57">s.104(1) Payment of Costs &amp; Expenses - Licensed</option>
<option value="60">s.104(1) Payment of Costs and Expenses - Non Licensed</option>
<option value="58">s.104(2) Payment of Costs &amp; Expenses - Licensed</option>
<option value="61">s.104(2) Payment of Costs and Expenses - Non Licensed</option>
<option value="59">s.104(3) Payment of Costs &amp; Expenses - Licensed</option>
<option value="62">s.104(3) Payment of Costs and Expenses - Non Licensed</option>
<option value="29">s.110 Revocation of Clean Up Notice</option>
<option value="34">s.110 Revocation of Prevention Notice</option>
<option value="37">s.110 Variation of Clean Up Notice</option>
<option value="36">s.110 Variation of Prevention Notice</option>
<option value="24">s.264 Noise Control Notice</option>
<option value="68">s.276 Noise Abatement Direction</option>
<option value="9">s.55 Licence Refusal</option>
<option value="38">s.55 Licence Transfer</option>
<option value="10">s.55 Licence Transfer Refusal</option>
<option value="12">s.58 Licence Variation</option>
<option value="49">s.78G Exemption - Cruise Shipping</option>
<option value="50">s.78N Approval - Cruise Shipping</option>
<option value="13">s.79 Revocation of a Licence</option>
<option value="15">s.79 Suspension of a Licence</option>
<option value="16">s.80 Surrender of a Licence</option>
<option value="25">s.81 Variation of a Revocation Condition</option>
<option value="39">s.81 Variation of a Surrender Condition</option>
<option value="67">s.81(3) Variation of a Suspension Condition</option>
<option value="71">s.91 Clean Up Notice</option>
<option value="64">s.91A Supplementary Clean Up Action</option>
<option value="76">s.92 - s.108A Clean-up Action</option>
<option value="48">s.92 Clean Up Notice</option>
<option value="22">s.96 Prevention Notice</option>
<option value="66">s.96A Supplementary Prevention Notice</option>
'''

soup = BeautifulSoup(html, 'html.parser')
texts = [option.get_text() for option in soup.find_all('option')]
print(texts)

This code will output a list of the text content inside each <option> tag:

['Approval under Control of Burning Reg', 'Court Ordered Modification', 'EHC Licence', 'Licence Bulk Variation', 'Load Reduction Agreement', 'Load Reduction Agreement - Termination', 'Penalty Notice', 'PRCE Act - s.36 Compliance Notice', 'PRCE Act - s.44 Revocation Notice', 'PRCE Act - s.44 Variation Notice', 's.104(1) Payment of Costs & Expenses - Licensed', 's.104(1) Payment of Costs and Expenses - Non Licensed', 's.104(2) Payment of Costs & Expenses - Licensed', 's.104(2) Payment of Costs and Expenses - Non Licensed', 's.104(3) Payment of Costs & Expenses - Licensed', 's.104(3) Payment of Costs and Expenses - Non Licensed', 's.110 Revocation of Clean Up Notice', 's.110 Revocation of Prevention Notice', 's.110 Variation of Clean Up Notice', 's.110 Variation of Prevention Notice', 's.264 Noise Control Notice', 's.276 Noise Abatement Direction', 's.55 Licence Refusal', 's.55 Licence Transfer', 's.55 Licence Transfer Refusal', 's.58 Licence Variation', 's.78G Exemption - Cruise Shipping', 's.78N Approval - Cruise Shipping', 's.79 Revocation of a Licence', 's.79 Suspension of a Licence', 's.80 Surrender of a Licence', 's.81 Variation of a Revocation Condition', 's.81 Variation of a Surrender Condition', 's.81(3) Variation of a Suspension Condition', 's.91 Clean Up Notice', 's.91A Supplementary Clean Up Action', 's.92 - s.108A Clean-up Action', 's.92 Clean Up Notice', 's.96 Prevention Notice', 's.96A Supplementary Prevention Notice']

Feel free to use this code as needed! If you have any further questions or need additional help, I'm here for you.

posted on 2025-02-19 10:17  McDelfino  阅读(6)  评论(0)    收藏  举报