🌶️🌶️🌶️
I decided to make a version of mine using regex instead of beautifulsoup:
temp_f = re.search("myforecast-current(.+?)>(.+?)°F", response.text)
temp_c = re.search("myforecast-current(.+?)>(.+?)°C", response.text)
print("The temperature in", place, "at", time.asctime() ,"is:")
print(temp_f.group(2), "F /", temp_c.group(2), "C") #with 2 wildcard queries, the temperature is in the second group as returned by re.search()
That works too. I would say regex is the harder way here compared to beautiful soup, but if you know regex already, then why not.
does anyone truly know regex? I have to look up how to search something every time :D
I know the logic, but I also have to look it up every time I need to use it. They say, if you have a problem that you have to solve with regex, now you have two problems.
I decided to make a version of mine using regex instead of beautifulsoup:
temp_f = re.search("myforecast-current(.+?)>(.+?)°F", response.text)
temp_c = re.search("myforecast-current(.+?)>(.+?)°C", response.text)
print("The temperature in", place, "at", time.asctime() ,"is:")
print(temp_f.group(2), "F /", temp_c.group(2), "C") #with 2 wildcard queries, the temperature is in the second group as returned by re.search()
That works too. I would say regex is the harder way here compared to beautiful soup, but if you know regex already, then why not.
does anyone truly know regex? I have to look up how to search something every time :D
I know the logic, but I also have to look it up every time I need to use it. They say, if you have a problem that you have to solve with regex, now you have two problems.