Python Forum
BeautifulSoup - extract table but not using ID
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BeautifulSoup - extract table but not using ID
#4
from bs4 import BeautifulSoup

html = '''\
<table style=" border-collapse: collapse;" border="0" cellPadding="0" summary="Transactions statistics summary table" class="750WidthClass">
  <tr bgcolor="330066">
    <td id="LraTransaction Name&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Transaction Name&nbsp;</span></td>
    <td id="Status" class="table_header" vAlign="top" width="80"><span class="Verdana2">SLA Status</span></td>
    <td id="LraMinimum&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Minimum&nbsp;</span></td>
    <td id="LraAverage&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Average&nbsp;</span></td>
    <td id="LraMaximum&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Maximum&nbsp;</span></td>
    <td id="LraStd. Deviation&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Std. Deviation&nbsp;</span></td>
    <td id="Lra80 Percent&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">80 Percent&nbsp;</span></td>
    <td id="LraPass&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Pass&nbsp;</span></td>
    <td id="LraFail&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Fail&nbsp;</span></td>
    <td id="LraStop&nbsp;" class="table_header_for_html_report" vAlign="top"><span class="Verdana2">Stop&nbsp;</span></td>
  </tr>
</table>'''

soup = BeautifulSoup(html, 'lxml')
table = soup.find(class_="750WidthClass")
verdana = table.select('.Verdana2')
for item in verdana:
    print(item.text)
Output:
Transaction Name  SLA Status Minimum  Average  Maximum  Std. Deviation  80 Percent  Pass  Fail  Stop 
Reply


Messages In This Thread
RE: BeautifulSoup - extract table but not using ID - by snippsat - Jan-04-2018, 11:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to extract style attribute with BeautifulSoup knight2000 1 3,085 Dec-28-2022, 03:06 AM
Last Post: knight2000
  Extract data from a table Bob_M 3 2,671 Aug-14-2020, 03:36 PM
Last Post: Bob_M
  Extract data with Selenium and BeautifulSoup nestor 3 3,912 Jun-06-2020, 01:34 AM
Last Post: Larz60+
  Beautifulsoup table question tantony 5 2,796 Sep-30-2019, 03:26 PM
Last Post: tantony
  BeautifulSoup: Error while extracting a value from an HTML table kawasso 3 3,220 Aug-25-2019, 01:13 AM
Last Post: kawasso
  How to get hyperlinks in to the table extracted by BeautifulSoup KenniT 2 4,935 Apr-04-2018, 10:05 AM
Last Post: DeaD_EyE
  BeautifulSoup - Table tkj80 6 9,759 Oct-21-2016, 01:23 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020