1

I'm using HtmlAgilityPack for get some soccer events from this site.

The event that I'm grabbing are inside the All tab. So essentially what I did is get the table where all events are located like this:

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 ']");

in the next time I get all the visible event, so all the div that have the class group-head expanded loaded:

var tableTrHeader = table.SelectNodes("//tr[@class='group-head expanded loaded  ']");

and next iterate it. All of this working good but I've a problem. Infact there are other event in the table, but unfortunately this doesn't have the class loaded but simply have: group-head clickable.

So I guess there is something in the js code of the site that perform an action or something like to get the details of clicked row.

I thought to load an html that have all the item expanded, but unfortunately I doesn't know an approach that allow me to send a click action on a specific target html element through c#. I suppose that HtmlAgilityPack is not done for this target but only for scraping.

Someone have a workaround for this? Thanks.

AgainMe
  • 760
  • 4
  • 13
  • 33

2 Answers2

2

I suppose that HtmlAgilityPack is not done for this target but only for scraping.

Right.

Someone have a workaround for this?

It heavily depends on how it is implemented. If it's JavaScript, then good luck. You probably need to switch your whole tool chain and use Browser automation instead.

If it's a HTML clickable link, get the link, make another request and parse it with HtmlAgilityPack again.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • Looking the site structure is all based on json, when I click on the row an http request is made and new details is loaded. So is all based on js. Unfortunately. – AgainMe Sep 02 '16 at 11:28
-2

I found this:

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
}

Here, take a look :)

Community
  • 1
  • 1
S. Medina
  • 76
  • 1
  • 8
  • Nope, this simulate a click on the window, I'm looking for something that simulate the click when the http request is sent, so I can get the html with all the classes `expanded loaded` – AgainMe Sep 02 '16 at 11:25