Python: Does not class analysis represent anything?
source link: https://www.codesd.com/item/python-does-not-class-analysis-represent-anything.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Python: Does not class analysis represent anything?
Trying to parse a weather page and select the weekly forecasted highs.
Normally I would search with tags = soup.find_all("span", id="hi")
but this tag doesn't use an id
it uses a class
.
Full code:
import mechanize
from bs4 import BeautifulSoup
my_browser = mechanize.Browser()
html_page = my_browser.open("http://www.wunderground.com/weather-forecast/45056")
html_text = html_page.get_data()
my_soup = BeautifulSoup(html_text)
tags = my_soup.find_all("span", class_="hi")
temp = tags[0].string
print temp
When I run this, nothing prints
The piece of HTML is buried inside a bunch of other tags, however the specific tag for today's high is as follows:
<span class="hi">63</span>
Just use class_
as the parameter name. See the docs.
The problem arises because class
is a Python keyword, so you can't use it directly.
Related Articles
Python does not consider equivalent objects to be equivalent
MySQL Connector in Python does not allow the syntax LOAD DATA INFILE
Python does not find modules in my package
Python Does Not Create Log File
Python Does Not Display the Result of Current Printing Instructions
What does Ruby have that Python does not have, and vice versa?
Why serializing json datetime objects in python does not work correctly for datetime objects
PHP python does not run PHP
The fundamental and essential matrix OpenCV (python) does not agree
Searching for and replacing Python does not work
Nested for loop in python does not embed the outer loop for
Python does not jump & ldquo; if [strg] or [strg] in variable & rdquo;
Python does not allow additional comments with env python
Python does not allow multiple return statements () in the ternary; A possible alternative that is also nice to aesthetics?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK