Hack Forums
[C#] c# grab data from url - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] c# grab data from url (/showthread.php?tid=5673911)



c# grab data from url - Shadyx - Jul 20, 2017

Hello guys,im wondering how could I get data from an external url so I can do a live price check of a certain item has the prices changes every 24h my app requires the value to update every 00:00.


* - Rageline - Jul 20, 2017

HtmlAgilityPack is a parser, if you mean directly from url there is Uri class in .NET


* - Shadyx - Jul 20, 2017

(Jul 20, 2017 03:09 AM)Rageline Wrote:  HtmlAgilityPack is a parser, if you mean directly from url there is Uri class in .NET

I have looked into htmlagilityPack,but doesn't it require acess to the website ftp to upload the file?

Edit: It's not from the actual url but from the page.


* - Shadyx - Jul 20, 2017

(Jul 20, 2017 03:42 AM)Rageline Wrote:  Stop doing drugs.

Are you actually going to help or what? stop flaming


* - goshmulticoloredalto - Jul 20, 2017

(Jul 20, 2017 05:56 AM)Shadyx Wrote:  Are you actually going to help or what? stop flaming

You could help us by giving details like the name of the website?
You'd probably want to use HttpWebRequest for getting the source of the page, then parse it for the price.


* - Shadyx - Jul 20, 2017

(Jul 20, 2017 06:05 AM)justsum1uknow Wrote:  You could help us by giving details like the name of the website?
You'd probably want to use HttpWebRequest for getting the source of the page, then parse it for the price.

Im sorry my bad, so the idea is to get today's price from this link http://www.grandexchangewatch.com/item/24431-fish-mask#.WXCuR9QrK9I

Has you open the page,you can see the prices by date,but the only price that I want to get from that page is today.

Thanks 🎉


* - Shadyx - Jul 20, 2017

(Jul 20, 2017 06:32 AM)Orka Wrote:  Data looks to be retrieved from ajax (their source is unobfuscated.) Try reversing it to save downloading and parsing a huge page.

How can I do that? Thanks for the help


* - NiÇŒa - Jul 20, 2017

To download a page you can use a WebClient. Specifically the DownloadString method.


* - Zilog80 - Jul 20, 2017

Code
view-source:http://www.grandexchangewatch.com/item/24431-fish-mask#.WXCuR9QrK9I

PHP Code

<?php 
[...]
</
tr>
<
tr class="tr-0">
<
td>July 19, 2017</td>
<
td>1,954,084gp</td>
<
td class="color-green" style="border-right: 1px solid #071D35;">+79,726gp</td>
<
td>July 9, 2017</td>
<
td>1,874,358gp</td>
<
td class="color-green" style="border-right: 1px solid #071D35;">+82,745gp</td>
</
tr>
[...] 

Price: 1,954,084gp

This can be 'parsed' without external dependencies in 2 minutes (3 minutes if you want 'pro' features)


* - NiÇŒa - Jul 20, 2017

(Jul 20, 2017 12:07 PM)Zilog80 Wrote:  
Code
view-source:http://www.grandexchangewatch.com/item/24431-fish-mask#.WXCuR9QrK9I

PHP Code

<?php 
[...]
</
tr>
<
tr class="tr-0">
<
td>July 19, 2017</td>
<
td>1,954,084gp</td>
<
td class="color-green" style="border-right: 1px solid #071D35;">+79,726gp</td>
<
td>July 9, 2017</td>
<
td>1,874,358gp</td>
<
td class="color-green" style="border-right: 1px solid #071D35;">+82,745gp</td>
</
tr>
[...] 

Price: 1,954,084gp

This can be 'parsed' without external dependencies in 2 minutes (3 minutes if you want 'pro' features)

Define 'pro' features.


* - Shadyx - Jul 21, 2017

(Jul 20, 2017 07:54 PM)NiÇŒa Wrote:  Define 'pro' features.

Thanks guys! you made it way more clear now,I had no idea how to do this,I might report the progress when im done with it.

Regards


* - +Haze - Jul 21, 2017

Ultimately you'd want to use a HTML parser to extract data from the HTML document. A parser like AngleSharp or HTMLAgilityPack works good. I prefer AngleSharp.


* - SL x TnT - Jul 23, 2017

(Jul 21, 2017 01:12 PM)+Haze Wrote:  Ultimately you'd want to use a HTML parser to extract data from the HTML document. A parser like AngleSharp or HTMLAgilityPack works good. I prefer AngleSharp.

The data he's looking for appears to be right here

Code
        var baseurl = "http:\/\/www.grandexchangewatch.com";
        var current_status = "completed";
        var status_posted_at = "1500736496";
        var session_id = "2E53iq7S58s3E1DibpIoxpqSls1ITc1pIsxVVkzwfY8sSUQd36bY9af7f4-9ixp8q4-dCb1nDlYKM1789tb3A-3a30SchNpvfa1tela";
        var item_id = "24431";
        var currenturl = "http:\/\/www.grandexchangewatch.com\/item\/24431-fish-mask";
        var notify_on = "You are receiving updates for this item via email";
        var notify_off = "You are not receiving updates for this item via email";
        var notify_on_img = "http:\/\/www.grandexchangewatch.com\/assets\/img\/notify-on.png";
        var notify_off_img = "http:\/\/www.grandexchangewatch.com\/assets\/img\/notify-off.png";
        var item_name = "Fish mask";
        var item_price = "1954084";

The values in the HTML are the historical prices.

Easy enough to grab using Regex.