C#: How to extract data from selection using web browser control RRS feed

  • Question

  • I have load a web site into my web browser control. user will select data from tabular data which i need to parse and populate in my data datagridview.

    this is the web site from where i need to parse data from selection. see the url

    see the screen shot where i have some selected text which i need to parse and load as data in datagridview.

    enter image description here

    i have done the code but not being able to extract data properly because i am extracting each line and then extracting each work by space. so where LI has space between then my idea is not working. so what would be best work out.

    Net revenue is a name of LI which has space but it is a LI name. so how to parse if LI has space between but will be extracted as single word?

    this code i have tried which is working partially

    private void Form1_Load(object sender, EventArgs e)
    private void button1_Click(object sender, EventArgs e)
        dynamic document = webBrowser1.Document.DomDocument;
        dynamic selection = document.selection;
        dynamic text = selection.createRange().text;
        var selectedtext = (string)text;
        string[] stringSeparators = new string[] { "\r\n" };
        string[] lines = selectedtext.Split(stringSeparators, StringSplitOptions.None);
        foreach (string s in lines)
        string sline = s;
        string[] words = sline.Split('\t');
        string Li = words[0];
        string value1 = words[1];
        string value2 = words[2];

    just tell me what logic i should used as a result LI name should be extracted as a single word even if there is space. as example Net Revenue is LI name.

    numeric value will be extracted as single value. if my objective is clear then please help with idea & sample code. thanks

    • Moved by CoolDadTx Wednesday, July 3, 2019 1:43 PM Winforms related
    Tuesday, June 25, 2019 7:57 PM

All replies

  • Hi,

     You need find a way to determine when the name ends and value1 and value2 begin. I am not familiar with the data, but it looks like contain text and values contain numbers (and parentheses and dollar sign). So take all the text as the name and then when you hit a numeral, paren, or dollar sign, that's the value. Alternately, they are probably using an html table underneath. If that's correct, you can use <td> tags as your separators. If you do that you may have a lot of html tags to wade through, but it should work.


    Ethan Strauss

    Tuesday, June 25, 2019 9:12 PM
  • Hi Sudip_inn, 

    Thank you for posting here.

    Based on my test, the string I got is not regular, so we can’t to get the correct result from the WebBrowser.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, June 27, 2019 9:47 AM
  • If the page is well formed look at

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, June 27, 2019 11:55 AM