Jump to content

So what I need is a simple script that receives an amount from another website and outputs it as raw text.

So theres 18.53 CHF currently HERE. That amount's always changing and i would like to "extract" this amount and have it as raw text shown on another website.

Is that possible?

 

-yali

99 Kid. Yes. A 'Youngster'.

World famous Couchpotatoe.

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/
Share on other sites

Link to post
Share on other sites

You could do it with DOM elements, search through and find what class/tag it's in and scan the HTML for it. Or you could take a look and see if they have some form of API, I would look for you but I can't understand a word :P

Bespoke Software Engineer

 

Laptop: MacBook Air (13-inch, Early 2015) - 8GB RAM - Intel Core i5 1.6GHz - Intel HD Graphics 6000 1536 MB

DesktopGAMEMAX Onyx - AMD FX6300 Black Edition 6 Core (Overclocked to 4.1GHz) - GIGABYTE NVIDIA GTX 1050Ti Overclocked - MSI NVIDIA GTX 750Ti Gaming 1085MHz - HyperX Savage 8 GB 1866 MHz DDR3 - MSI 970 Gaming - Corsair CP-9020015-UK - Kingston SSDNow UV400 120 GB Solid State Drive

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/#findComment-9433270
Share on other sites

Link to post
Share on other sites

5 minutes ago, Strayuru said:

You could do it with DOM elements, search through and find what class/tag it's in and scan the HTML for it. Or you could take a look and see if they have some form of API, I would look for you but I can't understand a word :P

Oh interesting :D Thanks!

99 Kid. Yes. A 'Youngster'.

World famous Couchpotatoe.

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/#findComment-9433288
Share on other sites

Link to post
Share on other sites

19 minutes ago, Strayuru said:

You could do it with DOM elements, search through and find what class/tag it's in and scan the HTML for it. Or you could take a look and see if they have some form of API, I would look for you but I can't understand a word :P

But how do I get that Element? I found it on the Website but how can i "copy" or "extract" it from there?

99 Kid. Yes. A 'Youngster'.

World famous Couchpotatoe.

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/#findComment-9433324
Share on other sites

Link to post
Share on other sites

17 minutes ago, Yali said:

But how do I get that Element? I found it on the Website but how can i "copy" or "extract" it from there?

You should be able to use something like jQuery's get method, and then write a script to parse for whichever class/tag the html you're after is in.

Bespoke Software Engineer

 

Laptop: MacBook Air (13-inch, Early 2015) - 8GB RAM - Intel Core i5 1.6GHz - Intel HD Graphics 6000 1536 MB

DesktopGAMEMAX Onyx - AMD FX6300 Black Edition 6 Core (Overclocked to 4.1GHz) - GIGABYTE NVIDIA GTX 1050Ti Overclocked - MSI NVIDIA GTX 750Ti Gaming 1085MHz - HyperX Savage 8 GB 1866 MHz DDR3 - MSI 970 Gaming - Corsair CP-9020015-UK - Kingston SSDNow UV400 120 GB Solid State Drive

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/#findComment-9433367
Share on other sites

Link to post
Share on other sites

12 minutes ago, Strayuru said:

You should be able to use something like jQuery's get method, and then write a script to parse for whichever class/tag the html you're after is in.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.get("http://www.finanzen.ch/rohstoffe/silberpreis/CHF", function(data, status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
</script>
</head>
<body>

<button>Button</button>

</body>
</html>

That's what i got so far. What else do i miss? I would need the data: part

Unbenannt.JPG

99 Kid. Yes. A 'Youngster'.

World famous Couchpotatoe.

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/#findComment-9433397
Share on other sites

Link to post
Share on other sites

Pointlessly using jQuery for basic DOM and XMLHttpRequest operations ... 9_9

 

But since you already added that nasty framework thingy, you could as well use it to parse the website. I assume you stored the HTML in a variable:

var elemente = $(deinHTML);
var silberpreisTH = $('.main_left .pricebox th:first', elemente);

The .html() attribute of silberpreisTH contains your value.

 

edit: Or, even better, get yourself an OpenExchangeRates account (it's free), they provide plain-text JSON files for exchange rates, easy to parse without jQuery.

Write in C.

Link to comment
https://linustechtips.com/topic/744568-simple-javascript/#findComment-9450857
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×