- def money(coinPrice):
-
import urllib
-
connection = urllib.urlopen("http://www.usagold.com/gold/price.html")
-
rate = connection.read()
-
connection.close()
-
currentLoc = rate.find("> coinPrice </A></div>")
-
if currentLoc != -1:
-
rateLocEnd = rate.rfind('</TD>', 0, currentLoc)
-
rateLocStart = rate.rfind('<TD width = "50">', 0, rateLocEnd)
-
rateCloseGold = rate[rateLocStart+4:rateLocEnd]
-
print "The price of", coinPrice, "Gold in US$ is", rateCloseGold
here is what I have, and the goal is to print out a statement that shows the closing price of gold in us dollars, by inputing what kind of gold you would like as an argument. I am not sure why this is ont working for me, it prints out much more than the 1 line in my print statement and I have copied a program that works properlly, but this one does not, I am guessing it has something to do with the fact that this one takes an argument. please help.
3 1574
Can I see the output please??
yes here it is, it prints out a very large portion of the website source, but i only need it to print the cost in US$ of whatever argument is passed through it.
I would like to note the output is about 5x longer than this but only posted the very beginning and end because it would not let me post the reply otherwise.
======= Loading Program ======= - >>> howMuch("Austrian")
-
The price of Austrian Gold in US$ is TYPE html>
-
<HTML>
-
<HEAD>
-
-
-
<META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Mac">
-
<TITLE>Todays Gold Coin Prices - closing price of gold bars and coins</TITLE>
-
<META NAME="description" CONTENT="End of day gold price quotes for coins and bullion, plus live gold coin prices, up to the minute">
-
<META NAME="keywords" CONTENT="gold coin prices, gold price, price of gold, price of gold coins, coin prices, coins">
-
<style type="text/css">
-
.txt9 {
-
font-family: Verdana, Geneva, sans-serif;
-
font-size: 9pt;
-
}
-
.txt8Center {
-
font-family: Verdana, Geneva, sans-serif;
-
font-size: 8pt;
-
text-align: center;
-
}
-
November 25, 2015 </TD>
-
<TD WIDTH="33%" BGCOLOR="#FFFFFF" NOWRAP><P align="center"> Spot gold price:<BR>
-
$ 1,071.06</TD>
-
<TD WIDTH="34%" BGCOLOR="#eeeeee"><P align="center"> Spot silver price:<BR>
-
$ 14.18
-
>>>
Either your scraping logic is wrong or the website changed its source code after you used your logic. I would suggest you to use. BeautifulSoup to extract the data.
BS is a third party library but famous due to is helpfulness.
Use BeautifulSoup to extract the table that has the required values.And then extract the required table row depending on the type of gold chosen by the user.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Guy Robinson |
last post by:
Hello,
I have a list of class instances. I wish to get the appropriate class attribute
in each class instance depending on a SINGLE keyword in the calling class.
How do I get the calling...
|
by: nuttydevil |
last post by:
Hey everyone! I'm hoping someone will be able to help me, cause I
haven't had success searching on the web so far... I have large chunks
of text ( all in a long string) that are currently all in...
|
by: sridhar |
last post by:
iam having user account on an exchangeserver.
with that can i send an email using python?
if iam using the following code iam getting error
fromAddress = 'sridhar_kasturi@satyam.com'...
|
by: Phoe6 |
last post by:
Hi all,
I am trying to disable the NIC card (and other cards) enabled in my
machine to test diagnostics on that card.
I am trying to disable it programmatic using python. I checked python
wmi and...
|
by: Nathan Pinno |
last post by:
How do I factor a number? I mean how do I translate x! into proper
Python code, so that it will always do the correct math?
Thanks in advance,
Nathan P.
| |
by: Vicent Giner |
last post by:
Hello.
I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.
However, it is usually said that Python is not a compiled but
interpreted programming...
|
by: Cirene |
last post by:
I created a 3.5 ASP.NET website using Teleriks Rad Controls.
It works fine locally, but when I deploy it to the server I get a
"Configuration Error". I am "renting" space on the server so I...
|
by: tinman486 |
last post by:
Im new to the whole javascript game, I know pretty much just enough to be dangerous with no real substance. Anyway Im trying to populate a DIV with a website using the URL as an inner html source
...
|
by: Amie |
last post by:
Afternoon,
I would like some help on how to create a website using the python
programming language.
I've tried using enamel, but had some problems because I could not
create html tables and...
|
by: Fredrik Lundh |
last post by:
leo davis wrote:
http://twill.idyll.org/
</F>
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| | |