Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************************
- ** **
- ** Codesnippets written by Madwin for MMP 2023 **
- ** **
- ** Not to be used freely. the code still has errors **
- ** It's intended to be used as starting point. **
- ** Code has not been checked and might still need **
- ** (a lot of) work. **
- ** **
- ** © MadMedia Productions 2023 **
- ** **
- ***********************************************************/
- /*
- C# method that you can use to get all meta elements from a web page
- loaded in a WebBrowser control:
- */
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace MetaFileGetter
- {
- public static class MetaFileGetter
- {
- public static List<HtmlElement> GetAllMetaFiles(WebBrowser webBrowser)
- {
- List<HtmlElement> metaElements = new List<HtmlElement>();
- foreach (HtmlElement metaElement in webBrowser.Document.GetElementsByTagName("meta"))
- {
- metaElements.Add(metaElement);
- }
- return metaElements;
- }
- }
- }
- /*
- This method takes a WebBrowser object as a parameter and returns a List
- of all meta elements found in the web page. The List is created and
- initialized to be empty at the beginning of the method.
- The method then loops through all meta elements in the web page using the
- GetElementsByTagName method of the HtmlDocument class. For each meta element
- found, it adds it to the List using the Add method of the List class.
- Finally, the method returns the List of meta elements.
- To use this method, you can call it and pass in a WebBrowser object that
- you have already navigated to the web page. For example:
- */
- WebBrowser webBrowser = new WebBrowser();
- webBrowser.Navigate("https://example.com");
- List<HtmlElement> metaElements = MetaFileGetter.GetAllMetaFiles(webBrowser);
- /*
- Note that this method simply returns a List of HtmlElement objects without
- filtering by name or any other attribute. You can modify the code to filter
- the List by attribute value or other criteria as needed.
- */
Advertisement
Add Comment
Please, Sign In to add comment