Sep-24-2019, 10:48 PM
Hi All,
just wanted to let you know that I was able to write the code :)
Thanks for all your help!!
just wanted to let you know that I was able to write the code :)
Thanks for all your help!!
import requests from bs4 import BeautifulSoup d=dict() def parsepage(page): soup = BeautifulSoup(page, 'lxml') table = soup.find_all('table')[7] if table is not None: trs = table.find_all('tr')[8:15] for n, tr in enumerate(trs): tds = tr.find_all('td')[:2] for n1, td in enumerate(tds): # print(f"\n------------------------------ tr_{n}, td_{n1} ------------------------------") # print(f"{td.prettify}") # print(td.contents) td = str(td) if td.find('LIBOR')>0: spos = td.find('">') epos = td.find('</a>') title = td[spos+2:epos] d[title]=d.get(title,0) if td.find('%')>0: spos = td.find('>') epos = td.find('%') rate = td[spos+1:epos-1] d[title] = rate else: print(f"Cound not find table") def scrape_url(url): response = requests.get(url) if response.status_code == 200: page = response.content parsepage(page) else: print(f"unable to retreive {url}") if __name__ == '__main__': url = 'https://www.global-rates.com/interest-rates/libor/libor.aspx' scrape_url(url) print(d)
Output:{'Euro LIBOR - overnight': '-0.56971', 'Euro LIBOR - 1 week': '-0.54743', 'Euro LIBOR - 2 weeks': 0, 'Euro LIBOR - 1 month': '-0.50200', 'Euro LIBOR - 2 months': '-0.44600', 'Euro LIBOR - 3 months': '-0.42529'}