473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a specific value from a website using python, takes an argument

6 New Member
Expand|Select|Wrap|Line Numbers
  1. def money(coinPrice):
  2.   import urllib
  3.   connection = urllib.urlopen("http://www.usagold.com/gold/price.html")
  4.   rate = connection.read()
  5.   connection.close()
  6.   currentLoc = rate.find("> coinPrice </A></div>")
  7.   if currentLoc != -1:
  8.     rateLocEnd = rate.rfind('</TD>', 0, currentLoc)
  9.     rateLocStart = rate.rfind('<TD width = "50">', 0, rateLocEnd)
  10.     rateCloseGold = rate[rateLocStart+4:rateLocEnd]
  11.     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.
Nov 27 '15 #1
3 1574
jaseel97
16 New Member
Can I see the output please??
Nov 28 '15 #2
jackie123
6 New Member
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 =======
Expand|Select|Wrap|Line Numbers
  1. >>> howMuch("Austrian")
  2. The price of Austrian Gold in US$ is TYPE html>
  3. <HTML>  
  4. <HEAD>
  5.  
  6.  
  7.   <META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Mac">
  8.   <TITLE>Todays Gold Coin Prices - closing price of gold bars and coins</TITLE>
  9.   <META NAME="description" CONTENT="End of day gold price quotes for coins and bullion, plus live gold coin prices, up to the minute">
  10.   <META NAME="keywords" CONTENT="gold coin prices, gold price, price of gold, price of gold coins, coin prices, coins">
  11. <style type="text/css">
  12. .txt9 {
  13.     font-family: Verdana, Geneva, sans-serif;
  14.     font-size: 9pt;
  15. }
  16. .txt8Center {
  17.     font-family: Verdana, Geneva, sans-serif;
  18.     font-size: 8pt;
  19.     text-align: center;
  20. }
  21. November 25, 2015 </TD>
  22.             <TD WIDTH="33%" BGCOLOR="#FFFFFF" NOWRAP><P align="center"> Spot gold price:<BR>
  23.                $ 1,071.06</TD>
  24.             <TD WIDTH="34%" BGCOLOR="#eeeeee"><P align="center"> Spot silver price:<BR>
  25.                $ 14.18 
  26. >>>
Nov 28 '15 #3
jaseel97
16 New Member
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.
Nov 29 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1503
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...
12
1539
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...
14
9865
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'...
4
14130
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...
14
7294
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.
53
5167
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...
3
4517
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...
6
4657
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 ...
2
1917
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...
0
855
by: Fredrik Lundh | last post by:
leo davis wrote: http://twill.idyll.org/ </F>
0
7086
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...
0
7460
tracyyun
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...
0
5578
agi2029
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,...
0
4672
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...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.