Jan-24-2019, 06:01 PM
(Jan-24-2019, 03:26 PM)b4iknew Wrote: My problem is one class_ has a variable of either high or low.Example with CSS Selector.
Now goes direct to values wanted,and
p.temp.temp
should work for both high and low.Direct for only high would be
p.temp.temp-high
.from user_agent import generate_user_agent from bs4 import BeautifulSoup import requests headers = {'User-Agent': generate_user_agent(device_type='desktop', os=('mac', 'linux'))} page_response = requests.get('https://forecast.weather.gov/MapClick.php?lat=32.47318000000007&lon=-100.40478999999999#.XC2EbM1MFEa/', timeout=5, headers=headers) soup = BeautifulSoup(page_response.content, 'lxml') temp = soup.select('p.temp.temp')[0] print(f'Today temp is {temp.text}')
Output:Today temp is High: 53 °F