C# 模拟点击html?
我正在使用C# 模拟点击html?,c#,html-agility-pack,C#,Html Agility Pack,我正在使用HtmlAgilityPack从中获取一些足球赛事 我抓取的事件位于All选项卡内。所以我所做的基本上是得到所有事件所在的表,如下所示: string url = "http://it.soccerway.com/"; string data = new WebClient().DownloadString(url); var doc = new HtmlDocument(); doc.LoadHtml(data); var table = doc.DocumentNode.Selec
HtmlAgilityPack
从中获取一些足球赛事
我抓取的事件位于All
选项卡内。所以我所做的基本上是得到所有事件所在的表,如下所示:
string url = "http://it.soccerway.com/";
string data = new WebClient().DownloadString(url);
var doc = new HtmlDocument();
doc.LoadHtml(data);
var table = doc.DocumentNode.SelectSingleNode("//table[@class='matches date_matches grouped ']");
在下一次中,我将获得所有可见事件,以便加载所有扩展了类组头的div
:
var tableTrHeader = table.SelectNodes("//tr[@class='group-head expanded loaded ']");
然后迭代它。这一切都很好,但我有个问题。事实上,表中还有其他事件,但不幸的是,它没有加载类,
,只是有:组头可单击
所以我猜在这个站点的js代码中有一些东西执行了一个操作或者类似的东西来获取点击行的详细信息
我本想加载一个扩展了所有项目的html,但不幸的是,我不知道如何通过c#在特定的目标html元素上发送单击操作。我认为HtmlAgilityPack
并不是针对这个目标而做的,只是针对刮取
有人能解决这个问题吗?谢谢。我找到了这个:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Form1 : Form
{
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public Form1()
{
}
public void DoMouseClick()
{
//Call the imported function with the cursor's current position
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
//...other code needed for the application
}
,看一看:)我发现了这个:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Form1 : Form
{
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public Form1()
{
}
public void DoMouseClick()
{
//Call the imported function with the cursor's current position
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
//...other code needed for the application
}
,看一看:)
我认为HtmlAgilityPack不是为这个目标而做的,只是为了刮取
对
有人能解决这个问题吗
这在很大程度上取决于它是如何实现的。如果是JavaScript,那么祝你好运。您可能需要切换整个工具链并使用浏览器自动化
如果它是一个HTML可点击链接,获取该链接,发出另一个请求,并再次使用HtmlAlityPack解析它
我认为HtmlAgilityPack不是为这个目标而做的,只是为了刮取
对
有人能解决这个问题吗
这在很大程度上取决于它是如何实现的。如果是JavaScript,那么祝你好运。您可能需要切换整个工具链并使用浏览器自动化
如果是HTML可点击链接,获取该链接,发出另一个请求并再次使用HtmlAlityPack解析它。您可以在windows窗体中使用WebBrowser执行点击事件和其他操作,您想在windows窗体应用程序中执行此操作吗?@LalitRajput不是windows窗体应用程序,但我使用的是WPF。好的,实际上,我是在Windows窗体应用程序中使用WebBrowser类完成的。WPF允许托管WebBrowser或类似控件。您可以在Windows窗体应用程序中使用WebBrowser执行单击事件和其他操作。您想在Windows窗体应用程序中执行此操作吗?@LalitRajput不是Windows窗体应用程序,但我使用的是WPF。好的,实际上,我是在Windows窗体应用程序中使用WebBrowser类实现的。WPF允许托管WebBrowser或类似控件。不,这模拟了在窗口上的单击,我正在寻找在发送http请求时模拟单击的东西,这样我就可以获得所有类扩展加载的html
Nope,这模拟了在窗口上的点击,我正在寻找一些东西来模拟发送http请求时的点击,这样我就可以得到所有类的htmlexpanded loaded
looking站点结构都是基于json的,当我点击行时,会发出http请求并加载新的详细信息。所有这些都是基于js的。不幸的是,站点结构都是基于json的,当我点击该行时,会发出http请求并加载新的详细信息。所有这些都是基于js的。不幸的是。