Hello, i've problems while downloading data from url. This is my code so far
Code byte[] raw = wc.DownloadData("url");
string webData = System.Text.Encoding.UTF8.GetString(raw);
TextBox9.Text = (webData);
but the problem is that the whole content is on one line, however the textbox is multiline, i've heard i had to do something with regex but not sure what.🤝 in advance.
Жизнь это не те дни, что прошли, а те, что запомнились
It depends on where you download it from. If you download http://site.com/document.txt, it will display it just fine. However, if you download an HTML data, you might have to replace some tags (e.g. p, br) with "\r\n", Environment.NewLine.
Not sure if you understood what I mean
Example:
Code WebClient wc = new WebClient();
byte[] raw = wc.DownloadData("url");
string webData = Encoding.UTF8.GetString(raw );
TextBox9.Text = webData.Replace("<br />", Environment.NewLine);
Aug 6, 2017 04:41 AM
(This post was last modified: Aug 6, 2017 05:20 AM by Dotexe.)
Yes it is an html data, and i had to replace these tags u mentioned, but i had no idea how to achieve it, i will do that when i get home and will let you know if works. Thank you !
EDIT: not working with this as well ;(
Жизнь это не те дни, что прошли, а те, что запомнились
Depending on how much markup there is and what you want to extract, it may be worthwhile using a parser such as htmlagilitypack.
Also, download directly as a string.
Aug 6, 2017 05:41 AM
(This post was last modified: Aug 6, 2017 05:45 AM by Electron.)
Can you give a sample from the input html.
Code TextBox9.Text = Regex.Replace(webData, "<.*?>", string.Empty);
This will remove all of the tags, but since you want to add new lines, this is not gonna work for you because you have to check which tag makes it go on a new line and then replace that tag with \r\n or Environment.NewLine. Because the new line may be coming by <p>some text</p>, some text<br />, div tag, etc.
(Aug 6, 2017 01:41 AM)Dotexe Wrote: Hello, i've problems while downloading data from url. This is my code so far
Code byte[] raw = wc.DownloadData("url");
string webData = System.Text.Encoding.UTF8.GetString(raw);
TextBox9.Text = (webData);
but the problem is that the whole content is on one line, however the textbox is multiline, i've heard i had to do something with regex but not sure what.🤝 in advance.
Can you show the website/markup and what you are trying to extract and format, please?
Aug 6, 2017 05:47 AM
(This post was last modified: Aug 6, 2017 05:49 AM by Dotexe.)
It is an raw, and has <p> i guess thats why i tried with \r\n but the same result, i will try with ur 2nd method
(Aug 6, 2017 05:46 AM)RickSanchez Wrote: Can you show the website/markup and what you are trying to extract and format, please?
It is https://hastebin.com/raw/itofofibug
Жизнь это не те дни, что прошли, а те, что запомнились
(Aug 6, 2017 05:47 AM)Dotexe Wrote: It is an raw, and has <p> i guess thats why i tried with \r\n but the same result, i will try with ur 2nd method
If you give url I can write the code, otherwise it's just guessing what exactly you're trying to achieve...
(Aug 6, 2017 05:50 AM)RickSanchez Wrote: If you give url I can write the code, otherwise it's just guessing what exactly you're trying to achieve...
Already did it, https://hastebin.com/raw/itofofibug , its not something special, just test each line
Жизнь это не те дни, что прошли, а те, что запомнились
(Aug 6, 2017 05:51 AM)Dotexe Wrote: Already did it, , its not something special, just test each line
Sorry op.
Anyway, what I see in this doc is
Test1
Test2
Test3
I tho thats the thing you wanted to see right ?
Жизнь это не те дни, что прошли, а те, что запомнились
(Aug 6, 2017 06:05 AM)Dotexe Wrote: I tho thats the thing you wanted to see right ?
The webpage you are parsing, the entire html markup of the page, or just give link to the page instead.
hastebin has some issues with the ssl btw, and I need to load it in wepbroxy...
Code TextBox9.Text = webData.Replace("\n", Environment.NewLine);
There you go
(Aug 6, 2017 06:11 AM)Electron Wrote: Code TextBox9.Text = webData.Replace("\n", Environment.NewLine);
There you go
Thank you, i tried with \r\n but havent with only \n , now it works, thanks to everyone else :)
Жизнь это не те дни, что прошли, а те, что запомнились
|