Answers for "how to load html file from pc in python using bs4"

0

how to load html file from pc in python using bs4

#!/usr/bin/python

from bs4 import BeautifulSoup

with open('index.html', 'r') as f:

    contents = f.read()

    soup = BeautifulSoup(contents, 'lxml')

    tags = soup.find_all(['h2', 'p'])

    for tag in tags:
        print(' '.join(tag.text.split()))
Posted by: Guest on March-18-2021

Code answers related to "how to load html file from pc in python using bs4"

Browse Popular Code Answers by Language