how to load html file from pc in python using bs4

Solutions on MaxInterview for how to load html file from pc in python using bs4 by the best coders in the world

showing results for - "how to load html file from pc in python using bs4"
Loukas
31 Jan 2021
1#!/usr/bin/python
2
3from bs4 import BeautifulSoup
4
5with open('index.html', 'r') as f:
6
7    contents = f.read()
8
9    soup = BeautifulSoup(contents, 'lxml')
10
11    tags = soup.find_all(['h2', 'p'])
12
13    for tag in tags:
14        print(' '.join(tag.text.split()))
15