Joel Company
Joel Company

Reputation: 40

How to scrape all h3 tags in a website using beautifulsoup4

Problem:- I want to get ALL the h3 tags in the webpage using only one line of code.

I know how to get tags and their innerHTML using beautifulsoup but only one at a time. Here is the basic code:-

from bs4 import BeautifulSoup
import requests

source = requests.get("https://en.wikipedia.org/wiki/Code").text

soup = BeautifulSoup(source, 'lxml')

content = soup.find("span")
spans = content
print(spans)

Output:

<span>...</span>

As seen above, it only returns one span, when i need all of the spans to appear as the output somewhat like:
<span>...</span>,<span>...</span> Please guide me to do this

Upvotes: 0

Views: 260

Answers (1)

Vikas Jadhav
Vikas Jadhav

Reputation: 4692

Try this

import bs4
soup1 = bs4.BeautifulSoup(htm1, 'html.parser')
for match in soup1.findAll('span'):
    match.unwrap()
print soup1

Upvotes: 2

Related Questions