I'm extremely new, so bear with me.
I have a webpage in xml displaying Earthquake information (Magnitude, place and etc.). I need to list each place and magnitude, which is located between <title> tags. The str.find() only works for one thing, but I need to list them all. Also, the page has an irrelevant title in the beginning and I need to start my search after that. This is what I have:
This only prints out that first irrelevant title between the title tags. I need to print the one after that.
And then I need to list all the titles after that one.
I know I need a while/loop, but I don't know how to skip the first irrelevant title.
This is basically the website:
<title>irreleva nt title</title>
<title>this is the title i need</title>
<title>then I need to list these</title>
<title>then I need to list these</title>
<title>then I need to list these</title>
<title>then I need to list these</title>
I hope this makes sense.
I have a webpage in xml displaying Earthquake information (Magnitude, place and etc.). I need to list each place and magnitude, which is located between <title> tags. The str.find() only works for one thing, but I need to list them all. Also, the page has an irrelevant title in the beginning and I need to start my search after that. This is what I have:
Code:
import urllib.request
def printEarthquakeTitle(requestedURL):
page = urllib.request.urlopen(requestedURL)
text = page.read().decode("utf8")
start = text.find("<title>") + 7
end = text.find("</title")
title = str(text[start:end])
return title
title = printEarthquakeTitle("http://earthquake.usgs.gov/eqcenter/catalogs/7day-M2.5.xml")
print(title)
And then I need to list all the titles after that one.
I know I need a while/loop, but I don't know how to skip the first irrelevant title.
This is basically the website:
<title>irreleva nt title</title>
<title>this is the title i need</title>
<title>then I need to list these</title>
<title>then I need to list these</title>
<title>then I need to list these</title>
<title>then I need to list these</title>
I hope this makes sense.
Comment