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

2

1 Answer 1

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']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.