Hi all,
I am a newbie on Python, forgive me if my question sounds silly. So I am trying to print out all the <a> url under each h2 section.
The html structure is like:
<div>
<h2>
<a href='xxxx'>
The content I want to print out 1
</a>
</h2>
<div>
<div>
<h2>
<a href='xxxx'>
The content I want to print out 2
</a>
</h2>
<div>
And the code I am using is like:
import requests
from bs4 import BeautifulSoup
r=requests.get("http://xxxxxxxxx/")
source_code = r.text
soup=BeautifulSoup(source_code,"html.parser").find_all("h2")
for link in soup:
print(link)
But how can I print out the results like:
The content I want to print out 1
The content I want to print out 2
Thanks a lot for the help!
BR,
Henry
I am a newbie on Python, forgive me if my question sounds silly. So I am trying to print out all the <a> url under each h2 section.
The html structure is like:
<div>
<h2>
<a href='xxxx'>
The content I want to print out 1
</a>
</h2>
<div>
<div>
<h2>
<a href='xxxx'>
The content I want to print out 2
</a>
</h2>
<div>
And the code I am using is like:
import requests
from bs4 import BeautifulSoup
r=requests.get("http://xxxxxxxxx/")
source_code = r.text
soup=BeautifulSoup(source_code,"html.parser").find_all("h2")
for link in soup:
print(link)
But how can I print out the results like:
The content I want to print out 1
The content I want to print out 2
Thanks a lot for the help!
BR,
Henry