- cefsharp を使用して、1 ページに 25 個のリンクを提供するページをロードしました。
FrameLoadEnd
取得した HTML コンテンツを HtmlAgilityPack ドキュメントに使用します。- 25 リンクのノードからタイトルを取得しました。 問題 ページ上の 50 個のリンクをクリックしてタイトルを取得しようとすると、25 個のリンクが表示されます。古いページです。ページ内の別のリンクに移動したときに FrameLoadEnd が html を変更できない理由がわかりませんでした。
50 タイトルをクリックすると、50 タイトルの HTML コンテンツを取得できません
ここにコードがあります
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CefSharp;
using CefSharp.WinForms;
using System.Windows.Forms;
using HtmlAgilityPack;
namespace Hummingbird_HAP_E_Scraper
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chromiumWebBrowser1.Load("https://www.sciencedirect.com/search?qs=nursing");
}
string html;
private void ChromiumWebBrowser1_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
BeginInvoke((Action)(async () =>
{
html = await chromiumWebBrowser1.GetSourceAsync();
}));
}
HtmlAgilityPack.HtmlDocument xdoc = new HtmlAgilityPack.HtmlDocument();
private void Button1_Click(object sender, EventArgs e)
{
xdoc.LoadHtml(html);
System.Threading.Thread.Sleep(5000);
HtmlNodeCollection links;
links = xdoc.DocumentNode.SelectNodes("//h2/span/a");
if (links == null)
return;
foreach (HtmlNode link in links)
{
listBox1.Items.Add(link.InnerText);
}
}
}
}