473,378 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Parsing HTML with C#

I want to extract a few simple elements from an HTML document
(Transitional 4.0, so not necessarily something that can be handled by
an XML parser). I've got as far as adding a reference to
Microsoft.mshtml, but now I don't know what's what.

The IHtmlDocument interfaces seem to be potentially helpful, but what
class implements those interfaces (i.e. how can I create an instance
with a "new" expression)? Basically, how do I get from a text file to
a model of the HTML contents in memory?

Eq.
Apr 24 '06 #1
2 4516
Paul E Collins wrote:
I want to extract a few simple elements from an HTML document
(Transitional 4.0, so not necessarily something that can be handled by
an XML parser). I've got as far as adding a reference to
Microsoft.mshtml, but now I don't know what's what.

The IHtmlDocument interfaces seem to be potentially helpful, but what
class implements those interfaces (i.e. how can I create an instance
with a "new" expression)? Basically, how do I get from a text file to
a model of the HTML contents in memory?


In 1.1 AxSHDocVw.AxWebBrowser.Document does. So, here is how it can
be done:

wb = new AxSHDocVw.AxWebBrowser();
object oNone = Type.Missing;
wb.Navigate("about:blank", ref oNone, ref oNone, ref oNone, ref oNone);
while (wb.Busy)
{
Application.DoEvents();
}
string htmlString = "<html><body>Hello</body></html>";
IHTMLDocument2 doc = wb.Document as IHTMLDocument2;
doc.clear();
doc.open(null, null, null, null);
doc.write(htmlString);
doc.close();

Now you can access whatever the interface provides.
Apr 24 '06 #2
Paul,
I think the best answer to this would revolve around the question "Where is
the HTML coming from". if you want something that will give you the
flexibility of treating even "poorly formed" HTML as XML, I'd recommend Simon
Mourier's
HTMLAgilityPack.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Paul E Collins" wrote:
I want to extract a few simple elements from an HTML document
(Transitional 4.0, so not necessarily something that can be handled by
an XML parser). I've got as far as adding a reference to
Microsoft.mshtml, but now I don't know what's what.

The IHtmlDocument interfaces seem to be potentially helpful, but what
class implements those interfaces (i.e. how can I create an instance
with a "new" expression)? Basically, how do I get from a text file to
a model of the HTML contents in memory?

Eq.

Apr 24 '06 #3

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
14
by: Viktor Rosenfeld | last post by:
Hi, I need to create a parser for a Python project, and I'd like to use process kinda like lex/yacc. I've looked at various parsing packages online, but didn't find anything useful for me: -...
9
by: RiGGa | last post by:
Hi, I want to parse a web page in Python and have it write certain values out to a mysql database. I really dont know where to start with parsing the html code ( I can work out the database...
0
by: Fuzzyman | last post by:
I am trying to parse an HTML page an only modify URLs within tags - e.g. inside IMG, A, SCRIPT, FRAME tags etc... I have built one that works fine using the HTMLParser.HTMLParser and it works...
3
by: Willem Ligtenberg | last post by:
I decided to use SAX to parse my xml file. But the parser crashes on: File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
1
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,...
4
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr>...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
4
by: Neil.Smith | last post by:
I can't seem to find any references to this, but here goes: In there anyway to parse an html/aspx file within an asp.net application to gather a collection of controls in the file. For instance...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.