473,854 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML Parsing in VB.Net

Does anyone have any good examples of parsing WebPages in VB.Net. My
application needs to get information from certain HTML tables and I haven't
been able to find a good way to approach the problem. I have researched
RegularExpressi ons but have found it to be rather complicated for what I am
attempting to accomplish. I was hoping that there would be some type of
utility that would allow me to parse through the webpage in a tree like
structure. I found one utility called HTMLAgilityPack but it seems to be a
little difficult to work with. If any one has any suggestions or examples I
would really appreciate it.

Thanks
Curtis
Nov 21 '05 #1
10 29503
Hi Curtis

If you want to access a web page as a tree structure then you are probably
looking at something like Microsoft's mshtml. It makes a page accessible as
a document object model (DOM), just like you might use automation to read a
Word document as a DOM. You can either get the page by using the WebBrowser
control (which wraps mshtml) in your application, or using mshtml directly.

Do you have your web page in memory, or are you also wanting to retrieve it
from the internet?

HTH

Charles
"Curtis" <cs*****@hotmai l.com> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl...
Does anyone have any good examples of parsing WebPages in VB.Net. My
application needs to get information from certain HTML tables and I
haven't been able to find a good way to approach the problem. I have
researched RegularExpressi ons but have found it to be rather complicated
for what I am attempting to accomplish. I was hoping that there would be
some type of utility that would allow me to parse through the webpage in a
tree like structure. I found one utility called HTMLAgilityPack but it
seems to be a little difficult to work with. If any one has any
suggestions or examples I would really appreciate it.

Thanks
Curtis

Nov 21 '05 #2
Hi Charles,

What now?

I am now telling to everybody to use the AgilityPack, just because that I
know that you know MsHtml well and found that AgilityPack easier to use.

How would I place this message from you now?

For me it is easier to tell MsHTML because than I can tell something more
about it if there are questions.

:-)

Cor
Nov 21 '05 #3
Hi Cor

I'm not sure I completely follow you ... I downloaded the AgilityPack some
time ago, but never really used it as I already had a lot invested in mshtml
and the WebBrowser control. Perhaps I should leave it to you or others to
recommend the AgilityPack?

Charles
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:uE******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Charles,

What now?

I am now telling to everybody to use the AgilityPack, just because that I
know that you know MsHtml well and found that AgilityPack easier to use.

How would I place this message from you now?

For me it is easier to tell MsHTML because than I can tell something more
about it if there are questions.

:-)

Cor

Nov 21 '05 #4
Charles,

Than I probably misunderstood you a while ago.

Never mind next time I advice use MSHTML again.

Cor
Nov 21 '05 #5
Thanks for the reply guys.

I have the HTML document stored in memory and I would need to load it in
that way. I don't didn't see a way to load an html document from a string in
the MSHTML class. I am already retrieving the web page through
HTTPWebRequest and HTTPWebResponse classes. The purpose of my application is
to scrape a particaluar webpage for contents of its tables which means the
programs end user doesn't need to see a the actual HTML documents coming
back to my application.

I have tried to use HTMLAgilityPack but found it a little bit difficult to
use. Does anyone have any good examples using the HTMLAgilityPack ?

Thanks,
Curtis

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Charles,

Than I probably misunderstood you a while ago.

Never mind next time I advice use MSHTML again.

Cor

Nov 21 '05 #6
Charles,

Thank you very much for your suggestions. I ended up using MSHTML after I
found an example that loads the HTML from memory. I used the following code,
any suggestions are welcome.

Public Function GetTableText(By Val sHTML As String) As String
Dim myDoc As mshtml.IHTMLDoc ument2 = New mshtml.HTMLDocu ment
Dim mElement As mshtml.IHTMLEle ment
Dim mElement2 As mshtml.IHTMLEle ment
Dim mECol As mshtml.IHTMLEle mentCollection
Dim I As Integer

'initialize the document object within the HTMLDocument class...
myDoc.close()
myDoc.open("abo ut:blank")
'write the HTML to the document using the MSHTML "write" method...

Dim clsHTML() As Object = {sHTML}
myDoc.write(cls HTML)
clsHTML = Nothing
mElement = myDoc.body()
mECol = mElement.getEle mentsByTagName( "TD")
For I = 0 To mECol.length - 1
mElement2 = mECol.item(I)
lstResults.Item s.Add(mElement2 .tagName & " : " & mElement2.inner Text)
Next
End Function

Thanks,
Curtis

"Charles Law" <bl***@nowhere. com> wrote in message
news:O6******** ******@TK2MSFTN GP09.phx.gbl...
Hi Curtis

If you want to access a web page as a tree structure then you are probably
looking at something like Microsoft's mshtml. It makes a page accessible
as a document object model (DOM), just like you might use automation to
read a Word document as a DOM. You can either get the page by using the
WebBrowser control (which wraps mshtml) in your application, or using
mshtml directly.

Do you have your web page in memory, or are you also wanting to retrieve
it from the internet?

HTH

Charles
"Curtis" <cs*****@hotmai l.com> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl...
Does anyone have any good examples of parsing WebPages in VB.Net. My
application needs to get information from certain HTML tables and I
haven't been able to find a good way to approach the problem. I have
researched RegularExpressi ons but have found it to be rather complicated
for what I am attempting to accomplish. I was hoping that there would be
some type of utility that would allow me to parse through the webpage in
a tree like structure. I found one utility called HTMLAgilityPack but it
seems to be a little difficult to work with. If any one has any
suggestions or examples I would really appreciate it.

Thanks
Curtis


Nov 21 '05 #7
Hi Curtis

That looks like a perfectly legitimate way to do it. The only thing that I
might perhaps do is [after open("about.bla nk")] check that, or wait for the
document to become ready. Html documents are loaded asynchronously, so the
Open can return before the operation is actually complete. Since the purpose
of opening about:blank it to initialise the document correctly, you could
start to write the html string before initialisation is complete, and upset
things.

HTH

Charles
"Curtis" <cs*****@hotmai l.com> wrote in message
news:OL******** *****@TK2MSFTNG P10.phx.gbl...
Charles,

Thank you very much for your suggestions. I ended up using MSHTML after I
found an example that loads the HTML from memory. I used the following
code, any suggestions are welcome.

Public Function GetTableText(By Val sHTML As String) As String
Dim myDoc As mshtml.IHTMLDoc ument2 = New mshtml.HTMLDocu ment
Dim mElement As mshtml.IHTMLEle ment
Dim mElement2 As mshtml.IHTMLEle ment
Dim mECol As mshtml.IHTMLEle mentCollection
Dim I As Integer

'initialize the document object within the HTMLDocument class...
myDoc.close()
myDoc.open("abo ut:blank")
'write the HTML to the document using the MSHTML "write" method...

Dim clsHTML() As Object = {sHTML}
myDoc.write(cls HTML)
clsHTML = Nothing
mElement = myDoc.body()
mECol = mElement.getEle mentsByTagName( "TD")
For I = 0 To mECol.length - 1
mElement2 = mECol.item(I)
lstResults.Item s.Add(mElement2 .tagName & " : " & mElement2.inner Text)
Next
End Function

Thanks,
Curtis

"Charles Law" <bl***@nowhere. com> wrote in message
news:O6******** ******@TK2MSFTN GP09.phx.gbl...
Hi Curtis

If you want to access a web page as a tree structure then you are
probably looking at something like Microsoft's mshtml. It makes a page
accessible as a document object model (DOM), just like you might use
automation to read a Word document as a DOM. You can either get the page
by using the WebBrowser control (which wraps mshtml) in your application,
or using mshtml directly.

Do you have your web page in memory, or are you also wanting to retrieve
it from the internet?

HTH

Charles
"Curtis" <cs*****@hotmai l.com> wrote in message
news:e0******** ******@TK2MSFTN GP09.phx.gbl...
Does anyone have any good examples of parsing WebPages in VB.Net. My
application needs to get information from certain HTML tables and I
haven't been able to find a good way to approach the problem. I have
researched RegularExpressi ons but have found it to be rather complicated
for what I am attempting to accomplish. I was hoping that there would be
some type of utility that would allow me to parse through the webpage in
a tree like structure. I found one utility called HTMLAgilityPack but it
seems to be a little difficult to work with. If any one has any
suggestions or examples I would really appreciate it.

Thanks
Curtis



Nov 21 '05 #8
Charles and Curtis,

Tomorrow I have probably ready an almost complete sample using MSHTML.

Now it is Ajax time. Charles knows probably what that means.

Cor
Nov 21 '05 #9
Curtis,

Here is the sample I was talking about yesterday.

http://www.windowsformsdatagridhelp....f-56dbb63fdf1c

I hope it helps,

Cor
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1646
by: SKG | last post by:
can any one help me with HTML Parsing Regular Expression or class. I need to parse all href tags with <A> elements. Thanks
3
2887
by: Sanjay Arora | last post by:
We are looking to select the language & toolset more suitable for a project that requires getting data from several web-sites in real- time....html parsing/scraping. It would require full emulation of the browser, including handling cookies, automated logins & following multiple web-link paths. Multiple threading would be a plus but not requirement. Some solutions were suggested: Perl:
0
1026
by: rufus | last post by:
I need to parse HTML output and find all instances of a word/phrase and then convert it to a link. We have a reasonably large product catalogue. If a particular product page contains the name of another product I want to convert the name into a link pointing to the page of that product. As the pages use mixed static and dynamic content it makes sense to parse and convert the HTML stream just before it is rendered. I would like...
6
1540
by: g_no_mail_please | last post by:
Python 2.3.5 seems to choke when trying to parse html files, because it doesn't realize that what's inside <!-- --> is a comment in HTML, even if this comment is inside <script> </script>, especially if it's a comment inside that script code too. The html file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>Choke on this</title> <script language="JavaScript">
1
2431
by: yonido | last post by:
hello, my goal is to get patterns out of email files - say "message forwarding" patterns (message forwarded from: xx to: yy subject: zz) now lets say there are tons of these patterns (by gmail, outlook, etc) - and i want to create some rules of how to get them out of the mail's html body. so at first i tried using regular expressions: for example - "any pattern that starts with a <p> and contains "from:"..." etc.
5
4282
by: mailtogops | last post by:
Hi All, I am involved in one project which tends to collect news information published on selected, known web sites inthe format of HTML, RSS, etc and sortlist them and create a bookmark on our website for the news content(we will use django for web development). Currently this project is under heavy development. I need a help on HTML parser.
1
8735
by: charlesvc | last post by:
Hallo I am working on web design on mobile. So i came to know for webpage in html or xhtml needs to be parsed to show on mobile So my doubt is the parsing will give only tags text and source etc. only, we have simulate it as a web page in canvas. I want to know whether my idea is correct or not. I found PocketLearn J2ME HTML Component. Here my doubt is whether the package webserver with this is available for dowload to use...
1
2495
by: worlman385 | last post by:
I need to parse the following HTML page and extract TV listing data using VC++ http://tvlistings.zap2it.com/tvlistings/ZCGrid.do any good way to extract the data? is easy for VC++ to call PERL script and do some regular expression? since the HTML page is not XML well formed, I cannot use a XML parser
3
4979
by: Kreauchee | last post by:
am at my wits end here (no stranger to JavaScripts but no guru by any stretch of the imagination). I've been struggling with this page for some time now and can't figure out why it just flat out does not work in ie7. It works in ie8, firefox, safari, opera, chrome, and my android phone's default browser. http://www.dharmatrading.com/html/eng/2298399-AA.shtml I don't even know how to debug it in ie7 since it seems to have no tools to do so...
0
9752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10766
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7083
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5946
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4167
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.