Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Still learning, class var?
#6
(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
Reply


Messages In This Thread
Still learning, class var? - by b4iknew - Jan-24-2019, 03:26 PM
RE: Still learning, class var? - by Larz60+ - Jan-24-2019, 03:36 PM
RE: Still learning, class var? - by b4iknew - Jan-24-2019, 03:47 PM
RE: Still learning, class var? - by Larz60+ - Jan-24-2019, 03:57 PM
RE: Still learning, class var? - by Larz60+ - Jan-24-2019, 05:15 PM
RE: Still learning, class var? - by snippsat - Jan-24-2019, 06:01 PM
RE: Still learning, class var? - by b4iknew - Jan-24-2019, 08:33 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020