미리 답변 해 주시면 사전에 사과드립니다 (정확한 위치를 알려주십시오). 웹, 유튜브 등을 며칠 동안 검색했지만 여전히 답변을 찾지 못했습니다.
다음 URL에서 일부 데이터를 추출하고 싶습니다. https://betcity.ru/en/results/sp_fl=a:46 ;
나는 오늘의 모든 이벤트 이름을 얻으려고 노력하고있다. (첫 번째는 Ho Kwan Kit / Wong Chun Ting - Fan Zhendong / Xu Xin과 그 이후의 모든 것들이다.) 내가 html의이 부분을 볼 수있는 요소를 검사 할 때 :
<div class="content-results-data__event"><span>Ho Kwan Kit/Wong Chun Ting — Fan Zhendong/Xu Xin</span></div>
나는 class = "content-results-data__event"로 모든 div를 얻고 그 div의 내부 텍스트를 얻는 것보다 생각했다. 코드를 실행할 때마다 결과가 0이됩니다. 왜 그런 클래스가있는 div가 있고 모든 이벤트를 얻을 수 있는지 (내가이 사이트에서 필요한 다른 정보를 얻을 수있는 방법을 배운다면) 노드를 얻지 못하는 이유는 무엇입니까? 여기에 내 코드가있다. (나는 이것에 상당히 새로운 것이다.)
public partial class Scrapper : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> Events = new List<string>();
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = NewMethod(web);
var Nodes = doc.DocumentNode.SelectNodes(xpath: "//div[@class='content - results - data__event'']").ToList();
foreach (var item in Nodes)
{
Events.Add(item.InnerText);
}
GridView1.DataSource = Events;
GridView1.DataBind();
}
private static HtmlDocument NewMethod(HtmlAgilityPack.HtmlWeb web)
{
return web.Load("https://betcity.ru/en/results/sp_fl=a:46;");
}
}
}
다음은 Selenium을 사용하여 하루 동안 HTML을 얻는 방법입니다. 나머지는 HtmlAgilityPack입니다. 이 사이트는 자체 서명 된 인증서를 사용하므로 자체 서명 된 인증서를 허용하도록 드라이버를 구성해야했습니다. 재미있게 보내십시오.
var ffOptions = new FirefoxOptions();
ffOptions.BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
ffOptions.LogLevel = FirefoxDriverLogLevel.Default;
ffOptions.Profile = new FirefoxProfile { AcceptUntrustedCertificates = true };
var service = FirefoxDriverService.CreateDefaultService();
var driver = new FirefoxDriver(service, ffOptions, TimeSpan.FromSeconds(120));
string url = "https://betcity.ru/en/results/date=2017-11-19;"; //remember to update the date accordingly.
driver.Navigate().GoToUrl(url);
Thread.Sleep(2000);
Console.Write(driver.PageSource);