score:2
Accepted answer
If you only need <script>
element nodes, use descendant-or-self (//
). Sample HTML:
var html =
@"<!doctype html system 'html.dtd'>
<html>
<head>
<link rel='stylesheet' href='../IRstyle.css' type='text/css'>
<title>Non-hierarchic document clustering</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<meta name='keywords' content=''>
<meta name='VW96.objecttype' content='Document'>
<script language='JavaScript' type='text/JavaScript'>
//Javascript-code goes here
</script>
</head>
<body>
<!--Body contents goes here-->
<!-- in footer -->
<script src='http://www.google-analytics.com/urchin.js' type='text/javascript'>
</script>
<script type='text/javascript'>
_uacct = 'UA-67XXXX-X';
urchinTracker();
</script>
</body>
</html>";
Parse sample:
var document = new HtmlDocument();
document.LoadHtml(html);
// target only <script> in <head>
// var scriptTags = document.DocumentNode.SelectNodes("//head/script");
var scriptTags = document.DocumentNode.SelectNodes("//script");
foreach (var script in scriptTags) script.Remove();
document.Save(OUTPUT);
Output:
<!doctype html system 'html.dtd'>
<html>
<head>
<link rel='stylesheet' href='../IRstyle.css' type='text/css'>
<title>Non-hierarchic document clustering</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<meta name='keywords' content=''>
<meta name='VW96.objecttype' content='Document'>
</head>
<body>
<!--Body contents goes here-->
<!-- in footer -->
</body>
</html>
Source: stackoverflow.com
Related Articles
- Use XPath to find all JavaScript type script elements
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- Could not find an implementation of the query pattern for source type
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet` 'Where' not found
- Getting "Could not find an implementation of the query pattern for source type 'ExcelQueryable<T>'. " Error
- Could not find an implementation of the query pattern for source type 'Join'
- Find a certain value from a source collection in a target collection of different type with linq
- error :Could not find an implementation of query for source type datatable and join not found while trying to join two datatables
- How do I find the text within a div in the source of a web page using C#
- Find if listA contains any elements not in listB
- Cannot compare elements of type 'System.Collections.Generic.ICollection`1 Only primitive types, enumeration types and entity types are supported
- Linq find all with certain type
- Find Elements by Attribute using XDocument
- Find first element of certain type in a list using LINQ
- Find all child controls of specific type using Enumerable.OfType<T>() or LINQ
- This code returns distinct values. However, what I want is to return a strongly typed collection as opposed to an anonymous type
- System.NotSupportedException - Cannot compare elements of type 'System.Linq.IQueryable
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Find elements existing in both collections using LINQ
- Use Linq to find consecutively repeating elements
- Is it just me? I find LINQ to XML to be sort of cumbersome, compared to XPath
- Given UIElementCollection, find all elements that have StyleA, and change them to StyleB in WPF
- LINQ Source Code Available
- How to find out if an object's type implements IEnumerable<X> where X derives from Base using Reflection
- .NET 4 Code Contracts: "requires unproven: source != null"
- How do I use Linq to find the elements of a list that are not present in another list?
- Cannot convert source type to target type List<KeyValuePair> Linq
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Find objects in list that match elements in array
- SQL left outer join, groupby & orderby to LINQ method query or method syntax
- Finding header value in xml
- Query string using LINQ
- Linq query to return country as column and cities as rows and count in cells
- Ambiguous Call In Linq-To-Sql Query
- Linq2sql Find Top Subscribers Question
- SQL-Using JOINS to get the values from three tables
- How to bind XAttribute Value by Foreach
- How to convert IEnumerable<IEnumerable<T>> to List<string>?
- LINQ expression node type is not supported in LINQ to Entities
- LINQ Anonymous Type, Custom Class, ObservableCollection and WPF - how does it hang together?
- Require Simplification On Linq To Assign Values To Dynamic Class Property
- C# Linq finding value
- c# Linq `List<Interface>.AddRange` Method Not Working
- How to compare two lists and set value to list property
- LINQ return type issues for sending eMail in C#
- LINQ - Displaying User's Friends' book list
- Select a property from duplicate records in ef core linq
- Show LINQ joined table column at view DisplayNameFor
- Calling the property names of a dynamic property "ints": can't call property