keep getting method not found errors with formprocessor addon

Topics: User Forum
Dec 9, 2009 at 3:18 PM

 

HtmlWeb hw = new HtmlWeb();
FormProcessor p = new FormProcessor(hw);


==> Form this_form = p.GetForm(txtLink, "/html[1]/body[1]/table[1]/tr[1]/td[2]/table[1]/tr[2]/td[1]/table[1]/tr[1]/td[1]/div[1]/div[1]/div[1]/table[1]/tr[1]/td[2]/form[1]", FormQueryModeEnum.Nested);
An unhandled exception of type 'System.MissingMethodException' occurred in HtmlAgilityPack.AddOns.FormProcessor.dll

Additional information: Method not found :translated from dutch) HtmlNodeEnumerator HtmlAgilityPack.HtmlNodeCollection.GetEnumerator().

 

 

i keep getting the above error message, the xpath i found out by experimenting in the direct window of visual studio, so it should be good, i tried nested and adjecent, txtlink is referring to a

fqdn http://www.somesite.com/ (i tried with and without trailing slash)

 

what can be wrong here

Sep 14, 2010 at 11:25 PM

I've got the same issue

I may have an idea: the addon FormProcessor has been released in 2006. At this time, HAP was V1.3.0

nowaday it's V1.4.0. Did the method HtmlAgilityPack.HtmlNodeCollection.GetEnumerator() disapeared between these two release ?

 

Sep 15, 2010 at 8:02 AM

I've found a page describing the "Getenumerator()" method:

http://www.kbs.uni-hannover.de/~minack/beagle++/beagle-0.0.13.2-doxygen/d6/dbf/classHtmlAgilityPack_1_1HtmlNodeCollection.html#41d4cdbf8efc35fe302c54870bd7623b

but I don't know whitch version it is...

Sep 15, 2010 at 1:37 PM

It says in the url HtmlAgilityPack 1_1 which I'm guessing is either HAP 1.1 or .NET 1.1

The HtmlNodeEnumerator was removed in 1.4.0. Html Agility Pack used to explicitly implement the IEnumerator,IEnumerable,IList interfaces which requires quite a bit of code. This was a necessary evil back in the .NET 1.0/1.1 days. With .NET 2.0 List<T> and IList<T> were added which do more of the heavy lifting and are compatible with LINQ expressions. By switching over to using List<T> internally and exposing IList<T> code complexity was reduced while usability of the API was greatly increase. Looks like FormProcessor hasn't been updated. I wasn't even aware of it's existence until now. 

With the new version it looks like a bunch of things in FormProcessor could be cleaned up and updated.

Version 1.3.0 is still available for download on codeplex, just scroll down the downloads list.

 

Sep 18, 2010 at 9:18 PM
Edited Sep 18, 2010 at 9:29 PM

Ok

I've tried to use HAPv1.3.0.

I tried like this:

public class MyClass
{
        private FormProcessor myFormProcessor;
        private HtmlDocument lastHtmlDocument;

        public MyClass()
        {
            myFormProcessor = new FormProcessor();

        }

        public HtmlDocument process(string MyValue1, string MyValue2)
        {
            HtmlDocument doc;

            try
            {


            Form form = myFormProcessor.GetForm(
                "http://www.MyWebSite.com",
                "//form[@name='MyForm']", FormQueryModeEnum.Nested);

            form["MyInput1"].SetAttributeValue("value", MyValue1);
            form["MyInput2"].SetAttributeValue("value", MyValue2);

            doc = myFormProcessor.SubmitForm(form);

            }
            catch (Exception e)
            {
                e.ToString();
                return null;
            }

            return doc;
        }
}

 

    class Program
    {
        static void Main(string[] args)
        {
            MyClass dummy = new MyClass();

            dummy.process("test", "test");

        }
    }

but it's bugging later at this method in HtmlAgilityPack.AddOns.FormProcessor :

        /// <summary>
        /// Gets the absolute URI.
        /// </summary>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public static Uri GetAbsoluteUri(Uri baseUri, string path)
        {
            Uri uriTarget;
            if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out uriTarget))
            {
                // See what type of URI it is...
                if (uriTarget.IsAbsoluteUri)
                {
                    return uriTarget;
                }
                else
                {
                    // Since it's not absolute, see whether it is relative to
                    // the current directory, or points to the web server root
                    if (uriTarget.OriginalString[0] == '/')
                    {
                        return new Uri(
                            new Uri(baseUri.Authority), // Its bugging HERE ! 
 uriTarget.OriginalString.Substring(1)); } else { return new Uri(GetBaseUri(baseUri), uriTarget); } } } else { return baseUri; } }

 

Do someone know for fact that FormProcessor did ever worked with any version of HAP ?

In this case, I'd like to know witch version of each dll.

 

Sep 19, 2010 at 8:30 PM
Edited Sep 19, 2010 at 8:34 PM

I've resolved the previous issue replacing

return new Uri(new Uri(baseUri.Authority),
 uriTarget.OriginalString.Substring(1));

by

                        Uri uri1 = new Uri(baseUri.AbsoluteUri, UriKind.Absolute); //instead of Uri uri1 = new Uri(baseUri.Authority);
                        Uri uri2 = new Uri( uri1 , uriTarget.OriginalString.Substring(1));
                        return uri2;

Now I'm bloqued on this problem:

the FromProcessor make a Loop (2 iterations)

the first time,e the HTML result is the same html code than the first form (amazing!) with a "OK" status code

the second, time the HTML result is empty, with this status code: "(417) Expectation Failed."