BeautifulSoup can't get pre tag

Question:

I need to get text from this page. But when I tried below, I get None output.

url = "http://www.koeri.boun.edu.tr/sismo/2/latest-earthquakes/list-of-latest-events/"

response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, "html.parser")

table = soup.find("pre")

print(table)

Instead html.parser, html5lib and lxml couldn’t help.

I found out that tag doesn’t exist on page-source. Something about dynamic page I guess. So is there a way to access it ?

Asked By: mu7u

||

Answers:

The <pre> tag is inside <iframe>, so try to load it from iframe source URL:

import requests
from bs4 import BeautifulSoup

url = "http://www.koeri.boun.edu.tr/scripts/lasteq.asp"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
print(soup.pre)

Prints:

<pre>

RECENT EARTHQUAKES IN TURKEY

KOERI REGIONAL EARTHQUAKE-TSUNAMI MONITORING CENTER

(QUICK EPICENTER DETERMINATIONS)

                                                        Magnitude

Date       Time      Latit(N)  Long(E)   Depth(km)     MD   ML   Mw    Region

---------- --------  --------  -------   ----------    ------------    -----------

2022.08.01 07:21:57  36.8547   29.2488        1.4      -.-  1.9  -.-   SOGUTLU-FETHIYE (MUGLA)                           Quick

2022.08.01 07:03:18  37.4368   36.9718        5.0      -.-  3.1  3.2   OKSUZLU-(KAHRAMANMARAS)                           Quick

...
Answered By: Andrej Kesely