0

Here is the given html given below

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" type="text/css">

    <div class="table-responsive grid_class">
    <table class="table lightgallery">
        <thead>
        <tr class="active">
            <th class="col-md-9">Col A</th>
            <th class="col-md-2">Col B</th>
        </tr>
        </thead>

        <tr>
            <td class="">               
            <span>some text here
            </span>
        </span>
        </span>
    </td>
        <td class="text-nowrap" style="font-size: 13px;"><span>some text here also</span></td>
        </tr>
       
        <tr>
            <td class="">               
            <span>some text here
            </span>
        </span>
        </span>
    </td>
        <td class="text-nowrap" style="font-size: 13px;"><span>some text here also</span></td>
        </tr>   
        
    </table>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>


How to get only the html not the library in python?

I tried urllib library and request library but it does not work

Any Help would be appreciated and thanks in Advance

Umair Mubeen
  • 823
  • 4
  • 22

1 Answers1

0

Just to read HTML you could use BeautfulSoup

#python -m pip install beautifulsoup4 lxml

from bs4 import BeautifulSoup

html = '''
 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" type="text/css">

    <div class="table-responsive grid_class">
    <table class="table lightgallery">
        <thead>
        <tr class="active">
            <th class="col-md-9">Col A</th>
            <th class="col-md-2">Col B</th>
        </tr>
        </thead>

        <tr>
            <td class="">               
            <span>some text here
            </span>
        </span>
        </span>
    </td>
        <td class="text-nowrap" style="font-size: 13px;"><span>some text here also</span></td>
        </tr>
       
        <tr>
            <td class="">               
            <span>some text here
            </span>
        </span>
        </span>
    </td>
        <td class="text-nowrap" style="font-size: 13px;"><span>some text here also</span></td>
        </tr>   
        
    </table>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
'''

soup = BeautifulSoup(html, 'lxml')

You can access variables and tags with .find[_all] or .select E.g.

ths = soup.find_all('th')
print([col.text for col in ths])
# ['Col A', 'Col B']
Prayson W. Daniel
  • 14,191
  • 4
  • 51
  • 57