html-agility-pack

Get a value of an attribute by XPath and HtmlAgilityPack

时光怂恿深爱的人放手 提交于 2020-01-09 05:10:49
问题 I have a HTML document and I parse it with XPath. I want to get a value of the element input, but it didn't work. My Html: <tbody> <tr> <td> <input type="text" name="item" value="10743" readonly="readonly" size="10"/> </td> </tr> </tbody> My code: using HtmlAgilityPack; HtmlAgilityPack.HtmlDocument doc; HtmlWeb hw = new HtmlWeb(); HtmlNodeCollection node = doc.DocumentNode.SelectNodes("//input/@value"); string s=node[0].InnerText; So I want to get the value: "10743" (and I don't mind to get

Get a value of an attribute by XPath and HtmlAgilityPack

廉价感情. 提交于 2020-01-09 05:09:23
问题 I have a HTML document and I parse it with XPath. I want to get a value of the element input, but it didn't work. My Html: <tbody> <tr> <td> <input type="text" name="item" value="10743" readonly="readonly" size="10"/> </td> </tr> </tbody> My code: using HtmlAgilityPack; HtmlAgilityPack.HtmlDocument doc; HtmlWeb hw = new HtmlWeb(); HtmlNodeCollection node = doc.DocumentNode.SelectNodes("//input/@value"); string s=node[0].InnerText; So I want to get the value: "10743" (and I don't mind to get

Parsing HTML to get script variable value

 ̄綄美尐妖づ 提交于 2020-01-09 03:21:05
问题 I'm trying to find a method of accessing data between tags returned by a server I am making HTTP requests to. The document has multiple tags, but only one of the tags has JavaScript code between it, the rest are included from files. I want to accesses the code between the script tag. An example of the code is: <html> // Some HTML <script> var spect = [['temper', 'init', []], ['fw\/lib', 'init', [{staticRoot: '//site.com/js/'}]], ["cap","dm",[{"tackmod":"profile","xMod":"timed"}]]]; </script>

I want to retrieve the width and height of html element with HtmlAgilityPack

筅森魡賤 提交于 2020-01-07 05:10:10
问题 How to retrieve the width and height of img element with HtmlAgilityPack I do this like this.. HtmlAgilityPack.HtmlAttribute width = link.Attributes["width"]; HtmlAgilityPack.HtmlAttribute height = link.Attributes["height"]; but the width and height is in most cases null. How to get the css height and width? 回答1: Basead in this page: page public sealed class UtilParserHTML { //Private Fields private Uri Uri; private Stream StreamPage; private HttpWebRequest HttpRequest; private

Get all elements in a NodeCollections

点点圈 提交于 2020-01-07 03:49:10
问题 I have an html file : <div class="form-wrapper"> <div></div> <div class="Clearfix"> <div></div> <div></div> <span></span><span class="time">Time</span> </div> <div></div> <div class="Clearfix"> <div></div> <div></div> <span></span><span class="time">Time1</span> </div> <div></div> <div class="Clearfix"> <div></div> <div></div> <span></span><span class="time">Time2</span> </div><div></div> <div class="Clearfix"> <div></div> <div></div> <span></span><span class="time">Time3</span> </div> I'm

Traversing back to the previous node using XPath in asp.net

我的未来我决定 提交于 2020-01-06 15:16:09
问题 I have asked a question about Traversing back to parent node in xpath i got expected reply, however i have one more doubt with the further development. With below HTML: <ul><li class="section">BROADCASTING</li> <ul> <li class="subsection"></li> <li class="circle"><a href="/article/95242-STATION_BREAK.php">STATION BREAK</a></li> <li class="circle"><a href="/article/98142-Labor_pains_hunger_pangs.php">Labor pains, hunger pangs</a></li> <li class="circle"><a href="/article/101509-Wake_up_call

Grabbing just the URL of an href using HTMLAgilityPack

送分小仙女□ 提交于 2020-01-06 08:20:26
问题 Here is the HTML source I'm trying to parse: <a style='white-space: nowrap;' href='/AuthorStories-4931/dreamfall.htm'><img class='donoricon' alt='(Current Donor)' title='(Current Donor)' src='http://static.tthf.me/images/donors/Current%20Donor.gif'/>dreamfall</a> Here is the code I'm using: authorLink = doc.DocumentNode.SelectSingleNode("//a[contains(@href, 'AuthorStories')]").OuterHtml; This grabs the link correctly, but it also captures the img as well. The only part I want to grab is the

Grabbing just the URL of an href using HTMLAgilityPack

对着背影说爱祢 提交于 2020-01-06 08:20:24
问题 Here is the HTML source I'm trying to parse: <a style='white-space: nowrap;' href='/AuthorStories-4931/dreamfall.htm'><img class='donoricon' alt='(Current Donor)' title='(Current Donor)' src='http://static.tthf.me/images/donors/Current%20Donor.gif'/>dreamfall</a> Here is the code I'm using: authorLink = doc.DocumentNode.SelectSingleNode("//a[contains(@href, 'AuthorStories')]").OuterHtml; This grabs the link correctly, but it also captures the img as well. The only part I want to grab is the

HTML Agility Pack Conversion to XML <script> corruption

99封情书 提交于 2020-01-06 06:32:33
问题 I've got an HTML file with a <script> in it: <html> <script type="application/custom+xml"> <my><xml><goes><here/></goes></xml></my> </script> </html> I parse it with HTML Agility Pack and then convert it to XML. HtmlDocument html; html.OptionOutputAsXml = true; html.Save(stream); ... XDocument xml = XDocument.Load(stream); I then want to use LINQ-to-XML to look at the contents of the script tag which should contain my XML as CDATA. But HTML Agility Pack messes it up somehow and I end up with

HtmlAgility ParseErrors Property

女生的网名这么多〃 提交于 2020-01-06 04:33:32
问题 What errors can I expect to fix HtmlAgility library? I know from my own experience it can close a missing tag, like: <car>Nissan</car When do Load or LoadHtml, it will fix it, like: <car>Nissan</car> I also know that ParseErorrs collection can determine Reason, Stream etc. Is there a list of errors (or can you tell from your own experience) how reliable is HtmlAgility for fixing errors and what errors cannot be fixed by HtmlAgility? 回答1: Historically, Html Agility Pack was never designed to