【发布时间】:2020-03-07 09:43:56
【问题描述】:
我正在尝试实现网络搜索以在 Google 搜索中获取网站标题。
我得到了一个在其他网站上运行良好的代码,但使用 Google 我得到了重复的结果。
我已经尝试过,但我看不出错误在哪里。
代码简化:
public partial class Form1 : Form
{
WebBrowser navegador = new WebBrowser();
private void Form1_Load(object sender, EventArgs e)
{
navegador.ScriptErrorsSuppressed = true;
navegador.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(this.datos);
}
private void datos(object sender, EventArgs e)
{
try
{
foreach (HtmlElement etiqueta in navegador.Document.All)
{
if (etiqueta.GetAttribute("classname").Contains("LC20lb DKV0Md"))
{
listBox1.Items.Add(etiqueta.InnerText);
}
}
}
catch (Exception exception) { }
}
private void function(object sender, EventArgs e)
{
/// string query = "https://google.com/search?q=" + query_box.Text;
navegador.Navigate("https://google.com/search?q=water");
/// this.Text = query;
}
}
结果:
【问题讨论】:
-
参见here 显示的注释和方法。一个类对象,存储结果和
GetHashCode()的使用,具体来说。
标签: c# winforms webbrowser-control