Reputation: 40
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
Reputation: 4692
Try this
import bs4
soup1 = bs4.BeautifulSoup(htm1, 'html.parser')
for match in soup1.findAll('span'):
match.unwrap()
print soup1
Upvotes: 2