8

Python: Does not class analysis represent anything?

 2 years ago
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.
neoserver,ios ssh client

Python: Does not class analysis represent anything?

advertisements

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

I am pickling, compressing, and saving python objects. I want to be able to double-check that that the object I saved is the exact same object that is returned after decompression and depickling. I thought there was an error in my code, but when I bo

MySQL Connector in Python does not allow the syntax LOAD DATA INFILE

I' m trying to send a text file into MySQL database. I am trying to do this with mysql connector in python 3.2. The problem is about LOAD DATA INFILE syntax. You can find my code above. My first question is is there anyway to solve this problem. Note

Python does not find modules in my package

I must be missing something very basic about building a package in Python. When I create a package following the guidelines of https://docs.python.org/2/tutorial/modules.html#packages and import it, Python does not find any of the modules. For exampl

Python Does Not Create Log File

I am trying to implement some logging for recording messages. I am getting some weird behavior so I tried to find a minimal example, which I found here. When I just copy the easy example described there into my interpreter the file is not created as

Python Does Not Display the Result of Current Printing Instructions

This question already has an answer here: Why does @foo.setter in Python not work for me? 4 answers This is probably trivial, but I got not resolution when searching for this: I have the following simple class: class Celcius: def __init__(self, tempe

What does Ruby have that Python does not have, and vice versa?

There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I pr

Why serializing json datetime objects in python does not work correctly for datetime objects

Why does the json serialization not work for datetime objects . As I understand json serialization the basic idea for any object can be call the __str__ builtin function and then urlencode the object that you get as a response. But in case of datetim

PHP python does not run PHP

hey yall. Im running python on a webserver from dreamhost. I am using their install of python and am using a lastfm module that can be found here: http://code.google.com/p/python-lastfm/ to get it to import properly i do this import sys sys.path.appe

The fundamental and essential matrix OpenCV (python) does not agree

I try to calibrate a stereo camera with OpenCV (python interface). I first calibrated the two cameras separately with calibrateCamera2 and then fed the parameters to stereoCalibrate cv.StereoCalibrate(object_points, image_points_left, image_points_ri

Searching for and replacing Python does not work

I have the following simple HTML file. <html data-noop=="http://www.w3.org/1999/xhtml"> <head> <title>Hello World</title> </head> <body> SUMMARY1 hello world </body> </html> I want to read this int

Nested for loop in python does not embed the outer loop for

I have two files: q.txt contains words and p.txt contains sentences. I need to check if any of the words in q.txt is present in p.txt. Following is what I wrote: #!/usr/bin/python twts=open('p.txt','r'); words=open('q.txt','r'); for wrd in words: for

Python does not jump & ldquo; if [strg] or [strg] in variable & rdquo;

This question already has an answer here: Why does `a == b or c or d` always evaluate to True? [duplicate] 1 answer I'm writing a simple text-based game in Python 2.7. In the code below, even if the user answers something completely different than "r

Python does not allow additional comments with env python

I have a commenting line problem in python. I created a ages.py with vim and here is my script #!/usr/bin/env python ages={"dad":42, "mom":35, "lisa":7} for item in ages: print item When I add a comment above the !/usr/bin, l

Python does not allow multiple return statements () in the ternary; A possible alternative that is also nice to aesthetics?

I am developing a text based RPG (graphics will be implemented later) and I am writing a method to determine whether a room a player is trying to go to exists or not. In this method I have multiple logic statements that determine what room the player

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK