Background traverses an HTML page

zhaozj2021-02-16  112

Write a program a few days ago, you need to traverse a dynamically generated page, find a specific node

So I wrote the following code:

Public class htmlreader {public htmlreader () {} ///

/// Search the node of a specific tag ///

///

///

///

Return to the attribute value

Public Static ArrayList SearchanTributes (String Inmarkup, String Keyword, String Attrname)

{

IHTMLDocument2 Doc = New HTMLDocumentClass ();

Doc.write (new object [] {inmarkup});

Doc.close ();

ArrayList searchList = new arraylist ();

Foreach (Ihtmlelement El in (IhtmlelementCollection) doc.body.all) {if (el.tagname.tolower () == keyword) {string src = el.getattribute (attrname, 0) .tostring (); // src = src .Remove (0, src.lastindexof ("/") 1); searchList.Add (src);}} returnof

}

转载请注明原文地址:https://www.9cbs.com/read-11062.html

New Post(0)