Hack Forums
[.NET] parse text from webpage - 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: [.NET] parse text from webpage (/showthread.php?tid=5783189)

Pages: Pages 1 2 3 4


parse text from webpage - Johan Cruyff - Jan 11, 2018

Hi,

I am trying to figure out how I can parse the text from this URL: https://poloniex.com/public?command=returnTicker

I wanna parse it in this format and later add it to a listview(which i can do myself), the only problem is i have no idea how to parse all that text into an array and loop through it.

Example:
Currency: BTC_BCN
last: 0.00000073
lowestAsk:0.00000073
highestBid:0.00000072
percentChange:-0.06410256
baseVolume:344.58554521
quoteVolume:460147932.89469838
isFrozen:0
high24hr:0.00000080
low24hr:0.00000070


RE: parse text from webpage - Ninja - Jan 11, 2018

It is JSON, so you should use JSON.net by NewtonSoft.


RE: parse text from webpage - Johan Cruyff - Jan 11, 2018

(Jan 11, 2018 09:37 AM)Ninja Wrote:  It is JSON, so you should use JSON.net by NewtonSoft.


I see it is a paid product, I'm not really looking to buy something like that since its not something I wanna resell in the future.
Is there any other way?


RE: parse text from webpage - Ninja - Jan 11, 2018

(Jan 11, 2018 11:08 AM)Johan Cruyff Wrote:  I see it is a paid product, I'm not really looking to buy something like that since its not something I wanna resell in the future.
Is there any other way?


It is free, only paid if you are a business. It is in the Nuget package manager in Visual Studio.


RE: parse text from webpage - iRtehBest - Jan 11, 2018

Use a WebRequest and Regex....


RE: parse text from webpage - Dialog - Jan 11, 2018

(Jan 11, 2018 11:50 AM)iRtehBest Wrote:  Use a WebRequest and Regex....


Just don't post if you have no clue what you're talking about.


RE: parse text from webpage - Sn0wX - Jan 11, 2018

Serialize and Deserialize JSON Data is already built into net classes :/

Look into DataContractJsonSerializer.


RE: parse text from webpage - System[X] - Jan 11, 2018

(Jan 11, 2018 12:08 PM)Dialog Wrote:  Just don't post if you have no clue what you're talking about.


Whats wrong with regex like ?

yes it can be bad if you get the pattern wrong and can create some hassle getting the pattern correct but honestly why use other classes and add modules to parse something from the web when regex can do it just fine with less lines of code and just as efficient.

If you know how to use regex the proper way then there is no problem using it. I have used many different methods and still prefer regex to them all, yes it can be a pain at time to get the correct pattern but its all the fun with coding and i love using regex for html or any web page to gather info from it.

Thanks


RE: parse text from webpage - Dialog - Jan 11, 2018

(Jan 11, 2018 12:34 PM)System[X] Wrote:  Whats wrong with regex like ?

yes it can be bad if you get the pattern wrong and can create some hassle getting the pattern correct but honestly why use other classes and add modules to parse something from the web when regex can do it just fine with less lines of code and just as efficient.

If you know how to use regex the proper way then there is no problem using it. I have used many different methods and still prefer regex to them all, yes it can be a pain at time to get the correct pattern but its all the fun with coding and i love using regex for html or any web page to gather info from it.

Thanks


Read some of the answers here: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags


RE: parse text from webpage - System[X] - Jan 11, 2018

(Jan 11, 2018 12:44 PM)Dialog Wrote:  Read some of the answers here: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags


Yes, i see. A good point there and should be used for the above link that i looked at after i posted(my fault).

But with other html web pages i would still prefer to use regex myself as i am extremely confident with using regex and get the pattern correct most of the time. To be honest tho i do remove "" from the webpage source before i proceed and also use plain text + regex in the patterns and also group them if needed. Maybe with me being old school and coding since vb6 and other languages well before that.

I see a few people say "ohh no, do NOT use regex" because they simply don't know how to use it correctly(not saying you, but a few people i see posting), its like when people say "ohh, no don't use .NET as a language".

Its always going to be same case when there is more than 1 method to use because people are different and believe too strongly in one method to try anything else. Its the same case in any language.

Always going to be good points and bad points.

Thanks


RE: parse text from webpage - Dialog - Jan 11, 2018

(Jan 11, 2018 01:01 PM)System[X] Wrote:  Yes, i see. A good point there and should be used for the above link that i looked at after i posted(my fault).

But with other html web pages i would still prefer to use regex myself as i am extremely confident with using regex and get the pattern correct most of the time. To be honest tho i do remove "" from the webpage source before i proceed and also use plain text + regex in the patterns and also group them if needed. Maybe with me being old school and coding since vb6 and other languages well before that.

I see a few people say "ohh no, do NOT use regex" because they simply don't know how to use it correctly(not saying you, but a few people i see posting), its like when people say "ohh, no don't use .NET as a language".

Its always going to be same case when there is more than 1 method to use because people are different and believe too strongly in one method to try anything else. Its the same case in any language.

Always going to be good points and bad points.

Thanks


It's not about "getting the pattern" right or not, but about the fact that regex just isn't suitable for context-free languages like HTML - that is not an opinion but a fact. Regex is a great and powerful tool and has many use cases, but parsing HTML is not one of them.
Recently I've been working on an app that valdiates passport document numbers. That's perfect for regex.


RE: parse text from webpage - System[X] - Jan 11, 2018

(Jan 11, 2018 01:09 PM)Dialog Wrote:  It's not about "getting the pattern" right or not, but about the fact that regex just isn't suitable for context-free languages like HTML - that is not an opinion but a fact. Regex is a great and powerful tool and has many use cases, but parsing HTML is not one of them.
Recently I've been working on an app that valdiates passport document numbers. That's perfect for regex.


So since regex can be used quite easily for this, its a fact that is should not be used over other methods that can parse the html because its not suitable for the job ?

OP, is it just the top line of the souce that you want ?
Code
{"BTC_BCN":{"id":7,"last":"0.00000073","lowestAsk":"0.00000074","highestBid":"0.00000073","percentChange":"-0.05194805","baseVolume":"314.38478290","quoteVolume":"421810741.82748085","isFrozen":"0","high24hr":"0.00000080","low24hr":"0.00000070"}


an easy regex pattern to be honest. Remove all the " from the source then its like plain text(no html tags)

Infact you could easily split the source on the first instance of "}" then use regex to separate the info into sections for variables.

Many ways of doing this task

Thanks


RE: parse text from webpage - Ninja - Jan 11, 2018

(Jan 11, 2018 12:13 PM)Sn0wX Wrote:  Serialize and Deserialize JSON Data is already built into net classes :/

Look into DataContractJsonSerializer.


The performance of NewtonSoft's library is far better than the DataContractJsonSerializer and the JavaScriptSerializer. Assuming, from the example, that OP is making a program that tracks market values of coins, a lot of requests will be made and thus speed is key. Besides, nothing wrong with using a third party library.


RE: parse text from webpage - Sn0wX - Jan 11, 2018

I have used Regex parsing data for years. No idea why systemx removes ". If you are using regular expressions use it. Only reason to remove a " because you don't really understand it. Basically a beginner.

Dialog, would you show me some solid proof that does not include One regex vs html famous post.

No regex i not ideal, it works easily when you take time to learn regular expressions.

So unless any One can offer advice, Guidance without quoting https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

I wait for your own extensive knowlegde answering my question.

Good story Ninja, why you even hear (said nicely)? If i wanted a begginers programming advice i'd contact wrox. Every day its post without and examples.

Tbh you are just a waste of air here getting a post count. 16 i guess? released any projects i can look at?

All yo do is use google. I suspect you are good at finding multiple returns and can use that info to pick what is correct.

Google boy 101


RE: parse text from webpage - Ninja - Jan 11, 2018

(Jan 11, 2018 01:14 PM)System[X] Wrote:  So since regex can be used quite easily for this, its a fact that is should not be used over other methods that can parse the html because its not suitable for the job ?

OP, is it just the top line of the souce that you want ?
Code
{"BTC_BCN":{"id":7,"last":"0.00000073","lowestAsk":"0.00000074","highestBid":"0.00000073","percentChange":"-0.05194805","baseVolume":"314.38478290","quoteVolume":"421810741.82748085","isFrozen":"0","high24hr":"0.00000080","low24hr":"0.00000070"}


an easy regex pattern to be honest. Remove all the " from the source then its like plain text(no html tags)

Infact you could easily split the source on the first instance of "}" then use regex to separate the info into sections for variables.

Many ways of doing this task

Thanks

I am unable to comprehend how you can suggest using Regex for JSON instead of a JSON parser, which exists in the .NET framework and in third party libraries, and is designed SPECIFICALLY for this job.

The worst thing is, you know you are wrong, yet you keep defending it and consciously teach beginners the wrong things.

(Jan 11, 2018 02:09 PM)Sn0wX Wrote:  Good story Ninja, why you even hear (said nicely)? If i wanted a begginers programming advice i'd contact wrox. Every day its post without and examples.

Tbh you are just a waste of air here getting a post count. 16 i guess? released any projects i can look at?

All yo do is use google. I suspect you are good at finding multiple returns and can use that info to pick what is correct.

Google boy 101


You keep saying that shit, but you never respond to my arguments with anything besides insults. Every time I make a point that is a fact and you have no legs to stand on you result to mindless insults. First in this thread https://hackforums.net/showthread.php?tid=5778012&pid=56493210 and now here. I even asked you to point out where I was wrong, but you resulted to passive aggressive insults, yet you call me a little boy all the time.