Fetching data from websites

This is the place for queries that don't fit in any of the other categories.

Fetching data from websites

Postby CaptainStecve » Wed Oct 30, 2013 11:13 pm

Good evening,

I was hoping to use Python, as an amateur, to credit a file that gets specific pieces of data from a website and then plugs them into a formula for my convenience.

The data I want to obtain is the "Recent Trade Price:" from these three links:
http://forums.zybez.net/runescape-2007- ... 5-iron-ore
http://forums.zybez.net/runescape-2007- ... iron-knife
http://forums.zybez.net/runescape-2007- ... of-forging

All I need is the number and then I should be able to get it to work, but I'm not very familiar with urllib. I'm coding in Python 3. Any advice from anyway?
Last edited by Yoriz on Wed Oct 30, 2013 11:47 pm, edited 1 time in total.
Reason: First post lock
CaptainStecve
 
Posts: 5
Joined: Wed Oct 30, 2013 11:09 pm

Re: Fetching data from websites

Postby CaptainStecve » Thu Oct 31, 2013 12:10 am

CaptainStecve wrote:Good evening,

I was hoping to use Python, as an amateur, to credit a file that gets specific pieces of data from a website and then plugs them


Woops, amateur English too. Create*, not credit

Anyone*, not anyway. It's too late for this.
CaptainStecve
 
Posts: 5
Joined: Wed Oct 30, 2013 11:09 pm

Re: Fetching data from websites

Postby micseydel » Thu Oct 31, 2013 12:13 am

urllib isn't difficult to use. And in the general case using regular expressions on html is tremendously discouraged, but if you're just looking for something very specific you'll likely be totally fine. We can provide more help once you've made and posted a code attempt (in code tags). The more specific your questions, the better.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1435
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Fetching data from websites

Postby CaptainStecve » Thu Oct 31, 2013 12:43 am

Code: Select all
ore = int(52) # I want this number to be sourced from http://forums.zybez.net/runescape-2007-prices/215-iron-ore from the recent trade price
knife = int(47) # Right now, assume this to be constant
ring = int(1622) # I want this number to be sourced from http://forums.zybez.net/runescape-2007-prices/1349-ring-of-forging from the recent trade price

number = float(input('How many ores do you want to use?: '))

if number > 140:
   print("For", int(number), "ores to be used,", int(number/140)+1, "Rings of Forging will be needed")
else:
   print("For", int(number), "ores to be used,", int(1), "Ring of Forging will be needed")
   
r = int(number/140)+1
   
print("The total cost of the ores right now will be", int(ore*number),"gp")
print("The total cost of the Rings of Forging right now will be", int(ring*r),"gp")

k = int(5*number)

print("Number of knives made =", k)
print("The total amount of money made from selling the knives made is", int(k*knife),"gp")

x = int(k*knife)
y = int(ore*number)
z = int(ring*r)
p = x - (y + z)

print("Therefore, the total profit right now from this is", p,"gp")
print("So, the percentage profit is", x/(y+z)*100,"%")

i = 37.5

print("The amount of Smithing experience gained from", int(number),"ores is", number*i,"xp")

input('Press ENTER to close the window')


I just threw that together. I want the values for "ore" and "ring" at the top to be taken from the "Recent Trade Price" on the webpages after the hashtag, but I don't know how to. Apologies for not specifying earlier.

All the int() tags are intentional, as the game I'm dealing with doesn't deal in decimal places.

The reason I use the input() tag at the end was because when I made documents in Python, they would always close instantly, but I found - on a forum - that by putting "input('')" the document would only close when ENTER was pressed. Sorry for multiple topics, but is that an issue with my installation or natural?
CaptainStecve
 
Posts: 5
Joined: Wed Oct 30, 2013 11:09 pm

Re: Fetching data from websites

Postby ochichinyezaboombwa » Thu Oct 31, 2013 3:55 am

So... what is your problem? Did you read the urllib documentation? have you tried to open and read a web page using it? Here, we usually don't help if you don't make an effort first, - unless it's posted in the "Jobs" forum.
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Fetching data from websites

Postby CaptainStecve » Thu Oct 31, 2013 11:12 am

ochichinyezaboombwa wrote:So... what is your problem? Did you read the urllib documentation? have you tried to open and read a web page using it? Here, we usually don't help if you don't make an effort first, - unless it's posted in the "Jobs" forum.


Apologies, again. I did my research and found the answer (I hope) to my solution. Thanks for the helpful push.
CaptainStecve
 
Posts: 5
Joined: Wed Oct 30, 2013 11:09 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests