So I'm trying to use the national weather service API to get a single element from a table. Specifically, I'm trying to get the current weather of where I live. The entire webpage is just one giant table and I haven't found a way to get information, besides printing everything beautiful soup grabs. How do I get the period 0 shortForcast information(if you go to the website) or how do I get started with the basic setup? Any help will be appreciated(also sorry for the extra imports, I've been trying a lot of different approaches).
import requests
from bs4 import BeautifulSoup
import lxml.html as lh
import pandas as pd
from html_table_parser import HTMLTableParser as pars
from pprint import pprint
URL = 'https://api.weather.gov/gridpoints/ILN/22,23/forecast/hourly'
def url_content(url):
req = urllib.request.Request(url=url)
f = urllib.request.urlopen(req)
return f.read()
def main():
xhtml = url_content(url).decode('utf-8')
p = pars()
p.feed(xhtml)
pprint(p.tables[0])
if __name__ == "__main__":
main()
This is the error if it helps, targeted at the "pprint(p.tables[0])" in the main method.
IndexError: list index out of range