简体   繁体   中英

Code not working after hosting on IIS 7.5

I am working on a MVC project. Here I am trying to get the elements of some other site. To get elements I am using WebBrowser Class object and the syntax goes like this :

var a = wb.Document.GetElementById("_menu__tableMenu").GetElementsByTagName("a");<br>
HtmlElement x = a[2];


where wb is instance of WebBrowser class This code works perfectly on my development machine and in my company's network (When hosted in one of our staging servers) But when I try to host it on client's hosting server it simply throws "Object reference not set to an instance " issue.

After logging errors I found out that this error is for HtmlElement x = a[2]; because array a doesn't have any item. But I am not able to understand why is it working this way where as all the elements I am looking for, exist.

I think that it can be a synchronization issue

A couple of thoughts:

You may try using the html agility pack: http://htmlagilitypack.codeplex.com/ I think it has better handling of DOM in various situations.

Does wb.Document.GetElementById(" menu _tableMenu") return anything, or is it also null?

Can you please show the code where you make your web request?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM