1

So essentially here is what i am trying to do, i want to save the whole html source text into a string, there i will be checking if it contains myvar. I have seen many other topics saying how to do this, but i tried them and end up with errors, i either enter a break state when i use .load("example.com"); or the string will end up containing the URL and not the actual HTML code.

Here is my code:

        string myString = "Pastebin";


        HtmlAgilityPack.HtmlDocument page = new HtmlAgilityPack.HtmlDocument();
        page.Load("https://pastebin.com");
        string text = page.DocumentNode.OuterHtml;


        if (text.Contains(myString))
        {
             MessageBox.Show("Yay!\n Match!");
            Instance = this;
            InitializeComponent();
            timer1.Start();
        }
        else
        {
            MessageBox.Show("Error...\nThe Var Doesnt match");
            Application.Exit();
        }
    }

Result:

Using .load("example.com"); The application enters a break state. using .loadhtml("example.com"); The application stores the URLand Not the HTML

pOleander
  • 11
  • 8

1 Answers1

0

Here is documentation. Use HtmlWeb to load html pages by url:

using HtmlAgilityPack;
//...

    HtmlWeb htmlWeb = new HtmlWeb();
    HtmlDocument htmlDoc = htmlWeb.Load("https://pastebin.com");
    string text = htmlDoc.Text;
Andrey Kotov
  • 1,344
  • 2
  • 14
  • 26
  • Wow i feel dumb now, yeah so that totally works, why are other people so adamant that the other way works? Maybe it worked in a different version. I got my previous information using this: https://stackoverflow.com/questions/5183385/htmlagilitypack-get-whole-html-document-as-string – pOleander May 31 '18 at 19:51
  • @pOleander using `page.Load` (from your code) you are able to load html from [**text**](http://html-agility-pack.net/from-string) or [**file**](http://html-agility-pack.net/from-file) but not from url. Here is the [**link**](http://html-agility-pack.net/parser) to all available html parsers for details. – Andrey Kotov May 31 '18 at 20:28
  • oh! i didnt realize thats how that works, so im guessing if i already had a html file, or had html code, that would be used to load the code, yeah that makes sense, also thats kinda cool too. xD thanks! – pOleander May 31 '18 at 22:25