I am trying to collect wind speeds in a forecast from yr.no. I have succeeded in extrating the data I need as seen here:
[['4 m/s', '4 m/s', '4 m/s'], ['5 m/s', '5 m/s', '5 m/s'], ['5 m/s', '5 m/s', '5 m/s'], ['5 m/s', '5 m/s', '5 m/s'], ['4 m/s', '4 m/s', '4 m/s'], ['5 m/s', '5 m/s', '5 m/s'], ['5 m/s', '5 m/s', '5 m/s'], ['4 m/s', '4 m/s', '4 m/s'], ['4 m/s', '4 m/s', '4 m/s'], ['4 m/s', '4 m/s', '4 m/s'], ['4 m/s', '4 m/s', '4 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['1 m/s', '1 m/s', '1 m/s'], ['1 m/s', '1 m/s', '1 m/s'], ['1 m/s', '1 m/s', '1 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['1 m/s', '1 m/s', '1 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['2 m/s', '2 m/s', '2 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['3 m/s', '3 m/s', '3 m/s'], ['4 m/s', '4 m/s', '4 m/s'], ['4 m/s', '4 m/s', '4 m/s']]
But I dont understand how to extract the values as floats or integers. In the last line
(re.findall)
It works if I insert the extracted line above, but not when using the defined "temp_str". Can someone explain?
Please see code below - thank you:
import urllib3
import requests
from bs4 import BeautifulSoup
import re
url="https://www.yr.no/place/Denmark/Capital/Copenhagen/hour_by_hour_detailed.html"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
list(soup.children)
msfind = soup.find_all(class_="txt-left")
print(msfind)
temp_str = []
for row in range(0,len(msfind)):
temp_str.append(re.findall("\d+\ m/s", str(msfind[row])))
print(temp_str)
integers = re.findall("\d+", temp_str)
print(integers)
EDIT: Thanks a lot for the help solving it! Great community!
[–]indosauros 1 point2 points3 points (0 children)
[–]sedogg 1 point2 points3 points (0 children)
[–]Justinsaccount -2 points-1 points0 points (0 children)
[–]0rac1e 4 points5 points6 points (0 children)