本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.LoadHtml方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.LoadHtml方法的具体用法?C# HtmlDocument.LoadHtml怎么用?C# HtmlDocument.LoadHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.LoadHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVideoLink
private static async Task<string> GetVideoLink(string link)
{
var httpClient = new HttpClient();
var response = await httpClient.GetStringAsync(link);
var doc = new HtmlDocument();
doc.LoadHtml(response);
var iframeLink = doc.DocumentNode.Descendants("body").
First().
Descendants("iframe").
First().
Attributes["src"].
Value;
response = await httpClient.GetStringAsync(iframeLink);
doc.LoadHtml(response);
var videoLink = response.Split('\"').
Where(part =>
part.Contains(".mp4") && part.StartsWith(@"http://")).
FirstOrDefault();
return videoLink;
}
示例2: ParseHtmlAsync
public async Task<string> ParseHtmlAsync(string tenant, string html)
{
var doc = new HtmlDocument();
doc.LoadHtml(html);
var nodes = doc.DocumentNode.SelectNodes("//include[@article-alias and @category-alias]");
if (nodes == null)
{
return html;
}
foreach (var node in nodes)
{
string alias = node.Attributes["article-alias"].Value;
string categoryAlias = node.Attributes["category-alias"].Value;
var model = await ContentModel.GetContentAsync(tenant, categoryAlias, alias).ConfigureAwait(false);
if (model != null)
{
string contents = model.Contents;
var newNode = HtmlNode.CreateNode(contents);
node.ParentNode.ReplaceChild(newNode, node);
}
}
return doc.DocumentNode.OuterHtml;
}
示例3: HtmlDocument
/// <summary>
/// New html document instance
/// </summary>
/// <param name="html"></param>
/// <returns></returns>
public HtmlDocument HtmlDocument(string html)
{
var d = new HtmlDocument();
d.LoadHtml(html);
return d;
}
示例4: ParseTopPerson
public static void ParseTopPerson(string html, Action<List<Person>> finished)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler((sender, e) =>
{
List<Person> TopPerson = new List<Person>();
HtmlDocument hDoc = new HtmlDocument();
hDoc.LoadHtml(html);
var tableRows = hDoc.DocumentNode.SelectNodes(Constants.Instance.XPATH_GAME_TOP_RESULT);
foreach (var node in tableRows)
{
var results = ChildElementsInTableRow(node);
if (results.Count == Constants.Instance.COUNT_GAME_TOP_RESULT_COLUMNS)
{
var person = TopPersonFromStrings(results);
if (person.Total != 0)
{
TopPerson.Add(person);
}
}
}
finished(TopPerson);
});
bw.RunWorkerAsync();
}
示例5: ParsePage
public static SteamApp ParsePage(int appId, string html)
{
if (string.IsNullOrWhiteSpace(html)) throw new ArgumentNullException(nameof(html));
try
{
var app = SteamApp.NewSteamApp(appId, html);
var htmlDocument = new HtmlDocument();
var htmlCleaned = html.Replace("\"", "'");
htmlDocument.LoadHtml(htmlCleaned);
var documentNode = htmlDocument.DocumentNode;
var titleNode = documentNode.SelectSingleNode($"//div[@class='{AppTitleClass}']");
app.Title = titleNode.InnerHtml.Trim();
var packageNodes = documentNode.SelectNodes($"//div[@class='{PackageClass}']").ToArray();
foreach (var packageNode in packageNodes)
{
AddPackage(app, packageNode);
}
return app;
}
catch (Exception)
{
throw new InvalidAppException(appId);
}
}
示例6: ParseRecommends
public static void ParseRecommends(string html, Action<List<Recommend>> finished)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler((sender, e) =>
{
List<Recommend> allRecommends = new List<Recommend>();
HtmlDocument hDoc = new HtmlDocument();
hDoc.LoadHtml(html);
var tableRows = hDoc.DocumentNode.SelectNodes(Constants.Instance.XPATH_GAME_SHOW_RESULT);
foreach (var node in tableRows)
{
var results = ChildElementsInTableRow(node);
if (results.Count == Constants.Instance.COUNT_GAME_SHOW_RESULT_COLUMNS)
{
var rec = RecommendFromStrings(results);
if (IsValidRecommend(rec))
{
allRecommends.Add(rec);
}
}
}
finished(allRecommends);
});
bw.RunWorkerAsync();
}
示例7: ConvertHtml
private void ConvertHtml(ExCSS.Stylesheet sheet, string html, Section section)
{
_sheet = sheet;
if (string.IsNullOrEmpty(html))
{
throw new ArgumentNullException("html");
}
if (section == null)
{
throw new ArgumentNullException("section");
}
//section.PageSetup.HeaderDistance = "0.001cm";
section.PageSetup.FooterDistance = Unit.FromCentimeter(0.01);
// Create a paragraph with centered page number. See definition of style "Footer".
var footer = section.Footers.Primary.AddParagraph();
//section.Footers.Primary.
footer.Format.Alignment = ParagraphAlignment.Right;
footer.AddPageField();
footer.AddText(" of ");
footer.AddNumPagesField();
var doc = new HtmlDocument();
doc.LoadHtml(html);
ConvertHtmlNodes(doc.DocumentNode.ChildNodes, sheet, section);
}
示例8: CreateRequest
public static HtmlDocument CreateRequest(string url)
{
using (var client = new HttpClient())
{
try
{
var response = client.GetAsync(url).Result;
if (response.StatusCode == HttpStatusCode.OK)
{
var responseContent = response.Content.ReadAsStringAsync().Result;
var doc = new HtmlDocument();
doc.LoadHtml(responseContent);
return doc;
}
else
{
throw new Exception(response.StatusCode.ToString());
}
}
catch (Exception e)
{
throw new Exception("Error executing query " + url + ". " + e.Message + " " + e.InnerException);
}
}
}
示例9: Parse
protected override void Parse(String page)
{
var doc = new HtmlDocument();
doc.LoadHtml(page);
var nodes = doc.DocumentNode.SelectNodes("//ul[@class='list']//li");
if (nodes != null)
{
foreach (var node in nodes)
{
var sale = false; //из списка нельзя получить инфу о скидке, поэтому всегда false
var title = node.SelectSingleNode(".//div[@class='title']").FirstChild.InnerText.Replace("\r\n", " ");
var searchString = DelBadChar(ref title);
var gameUrl = StoreUrl + node.SelectSingleNode(".//a").GetAttributeValue("href", String.Empty);
var cost = node.SelectSingleNode(".//div[@class='price']//span[@class='new']").InnerText;
_entries.Add(new GameEntry()
{
SearchString = searchString,
StoreUrl = StoreUrl,
Title = title,
GameUrl = gameUrl,
Cost = cost,
Sale = sale
});
}
}
}
示例10: btnTestCode_Click
private void btnTestCode_Click(object sender, RoutedEventArgs e)
{
var mainPage = GetHtml("http://htmlagilitypack.codeplex.com");
var homepage = new HtmlDocument();
homepage.LoadHtml(mainPage);
var nodes =
homepage.DocumentNode.Descendants("a").Where(x => x.Id.ToLower().Contains("releasestab")).FirstOrDefault
();
var link = nodes.Attributes["href"].Value;
var dc = new HtmlDocument();
try
{
Cursor = Cursors.Wait;
var req = (HttpWebRequest) WebRequest.Create(link);
using (var resp = req.GetResponse().GetResponseStream())
using (var read = new StreamReader(resp))
{
dc.LoadHtml(read.ReadToEnd());
var span =
dc.DocumentNode.Descendants("span").Where(
x => x.Id.ToLower().Contains("releasedownloadsliteral")).FirstOrDefault();
MessageBox.Show(
int.Parse(span.InnerHtml.ToLower().Replace("downloads", string.Empty).Trim()).ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading file: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error,
MessageBoxResult.OK);
}
}
示例11: GetForms
public IEnumerable<HtmlForm> GetForms()
{
var doc = new HtmlDocument();
doc.LoadHtml(Content);
var forms = doc.DocumentNode.SelectNodes("//form");
return forms.Select(HtmlForm.FromNode);
}
示例12: GetFundamentals
static IDictionary<string, string> GetFundamentals(Uri url)
{
string html;
using (var webClient = new WebClient())
html = webClient.DownloadString(url);
var doc = new HtmlDocument
{
OptionFixNestedTags = true
};
doc.LoadHtml(html);
var fundamentals = new Dictionary<string, string>();
var trs = doc.DocumentNode.SelectNodes("//div[@data-ajax-name='EquitySummaryTable']//table[contains(@class, 'horizontalTable')]//tr");
if (trs == null)
return fundamentals;
foreach (var tr in trs)
{
var name = tr.Elements("th").Single().InnerText;
var value = tr.Elements("td").Single().InnerText;
if (value == "--")
{
Log.DebugFormat("Missing: {0} = {1}", name, value);
continue;
}
Log.DebugFormat("Found: {0} = {1}", name, value);
fundamentals.Add(name, value);
}
return fundamentals;
}
示例13: ReplaceTags
private string ReplaceTags(string html)
{
var doc = new HtmlDocument();
doc.LoadHtml(html);
var divs = doc.DocumentNode.Descendants("div").Where(d =>
d.Attributes.Contains("class")).ToList(); //&& d.Attributes["class"].Value.Contains("editable-wrapper"));
var editableDivs = new List<HtmlNode>();
foreach (var div in divs)
{
if(div.Attributes["class"].Value.Contains("editable-wrapper"))
{
editableDivs.Add(div);
}
}
foreach (var editableDiv in editableDivs)
{
editableDiv.AppendChild(GetEditButtonElement());
editableDiv.AppendChild(GetSaveButtonElement());
}
return doc.DocumentNode.OuterHtml;
}
示例14: ItemCrawler
public ItemCrawler(Uri url)
{
_htmlDocument = new HtmlDocument();
var html = new WebClient().DownloadString(url.OriginalString);
_htmlDocument.LoadHtml(html);
_document = _htmlDocument.DocumentNode;
}
示例15: RefreshAsync
/// <summary>
/// 非同步刷新最新資訊
/// </summary>
/// <returns></returns>
public async Task RefreshAsync() {
HttpClient client = new HttpClient();
HtmlDocument HTMLDoc = new HtmlDocument();
HTMLDoc.LoadHtml(await client.GetStringAsync(DataSource));
var script = HTMLDoc.DocumentNode.Descendants("script")
.Where(x => x.InnerHtml?.Length > 0).Select(x => x.InnerHtml).ToArray();
var tempAry = script.First()
.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select((x, i) => new { index = i, item = x })
.GroupBy(x => Math.Floor(x.index / 4.0));
this.LastPassed = null;
this.Delay = new TimeSpan();
foreach (var item in tempAry) {
string[] temp = item.Select(x=>x.item).ToArray();
if(temp[3] == "TRSearchResult.push('x')") {
this.LastPassed = await Station.GetStationByNameAsync(
innerString(temp[0],"'","'")
);
}
}
var time = new TimeSpan(0, int.Parse(innerString(script.Last(), "=", ";")),0);
this.Delay= time;
}