Hack Forums
[C#] Retrieve 2 dynamic value from HTTP Response - 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#] Retrieve 2 dynamic value from HTTP Response (/showthread.php?tid=5166649)



Retrieve 2 dynamic value from HTTP Response - dbzdivik - Feb 11, 2016

hi Guys,

I need a little Help regarding retrieving 2 dynamic values from Http Web Response content.

I save response content in page.html and use HTML agility pack to retrieve some values example

Response
Code
<input name="static" value="dynamic">

my code
Code
doc.Load(Application.StartupPath + @"\\page.html");
string abc = doc.DocumentNode.Descendants("input").First(i => i.Attributes["name"] != null && i.Attributes["name"].Value == "static").Attributes["value"].Value;

but i need help for a this Response
Code
<input name="static:dynamic" value="dynamic">

1. I cant use above code as that wouldn't work
2. whole response has 1173+ line so regex is taking too much time to read
3. Also this
Code
<input name ="static
this occurs 15 time in whole response content...

So is there any way how can i get both dynamic values

Please help


* - Benoit ᵇᵃˡˡˢ - Feb 11, 2016

You can use LoadHtml and not save it to file, other than that, try finding it by XPath.


* - stackoverflowin - Feb 11, 2016

PHP Code

<?php 
new Regex('<input name="static" value="(.*?)">', new WebClient().DownloadString("http://google.com/page.html")).Match.Group[1].Value; 



* - +Haze - Feb 11, 2016

(Feb 11, 2016 11:37 AM)StackOverlowin Wrote:  
PHP Code

<?php 
new Regex('<input name="static" value="(.*?)">', new WebClient().DownloadString("http://google.com/page.html")).Match.Group[1].Value; 

Jesus christ. What a mess, I thought you was a pro? Nice memory leak.


* - Forecraft - Feb 11, 2016

@StackOverlowin
That is a pretty inefficient way of doing it, as XPath can be used directly.


* - dbzdivik - Feb 11, 2016

(Feb 11, 2016 10:37 AM)๖ۣۜLeonardo Da Vinci Wrote:  You can use LoadHtml and not save it to file, other than that, try finding it by XPath.

I need Response content in page.html to find out if some error occur while running so i got to know where my error is coming from.
I'll try xpath Thanks but a example code would be nicer..

(Feb 11, 2016 11:37 AM)StackOverlowin Wrote:  
PHP Code

<?php 
new Regex('<input name="static" value="(.*?)">', new WebClient().DownloadString("http://google.com/page.html")).Match.Group[1].Value; 

I already wrote that response content has over 1173+ lines so regex is taking too much time to read every line + if you had noticed
Code
<input name="static:[b]dynamic[/b]" value="dynamic">



* - Zuro - Feb 12, 2016

(Feb 11, 2016 12:00 PM)+Haze Wrote:  Jesus christ. What a mess, I thought you was a pro? Nice memory leak.

Yes, nice memory leak with a CLR that removes anonymous class instances as soon as they go out of scope.


* - dbzdivik - Feb 12, 2016

(Feb 11, 2016 10:37 AM)๖ۣۜLeonardo Da Vinci Wrote:  You can use LoadHtml and not save it to file, other than that, try finding it by XPath.

Hi i did some google how to use that but i think xpath can be used with tags and all like list or table etc....
but there is no table or list...

just
Code
</table><input type="hidden" name="static:dynamic" value="dynamic"><input type="hidden" name="static">....

Please A little bit more help would be great


* - dbzdivik - Mar 18, 2016

(Mar 9, 2016 12:22 PM)Electroalek Wrote:  I would actually suggest a custom find method. You probably know approximately where that input element is in the whole document. So just loop within that range and do a manual look-ahead for the needed characters, if you can find them parse the value that way. This way you will keep the find cost low. Of course you can do a substring from a smaller portion, again the approximate location of the input element and then use regex on it, instead of the whole string. With the first method you can also use a streamreader and directly read as it downloads the stream, so it will be super efficient.

Thanks for reply..
I did that what you ask but unfortunately all other input tag elements are in same table where my required data is but it is in last of that table tag.
So can you tell how to just neglect rest input tag and just read last input tag in table tag.


* - Verizur - Mar 18, 2016

May I have the full site url so that I can try this?


* - dbzdivik - Mar 18, 2016

(Mar 18, 2016 10:40 AM)Verizur Wrote:  May I have the full site url so that I can try this?

Bro I send a skype request to your following signature name.

BTW it's a response code so if i share url it wouldn't work according to needed.