Я пытаюсь получить некоторые данные с веб-страницы с помощью HtmlAgilityPack, который получает некоторые переменные и дает некоторые результаты. Я хочу получить 3 поля данных с этой веб-страницы, и пока я могу получить только 2 из них. Мой код до сих пор
struct Result
{
public string Description;
public string thirdCountryDuty;
public string tarifPreference;
}
private Result LoadWebPage(string url, string taric)
{
//This is the webpage which contains all three datas that I want. I just write it here as
url for testing
url = "https://ec.europa.eu/taxation_customs/dds2/taric/measures.jsp?Lang=en&SimDate=20200503&Area=SG&MeasType=&StartPub=&EndPub=&MeasText=&GoodsText=&op=&Taric=6213900010&search_text=goods&textSearch=&LangDescr=el&OrderNum=&Regulation=&measStartDat=&measEndDat=%22;"
var result = new Result();
taric = "6213900010";//This is a variable. I give it here for testing purposes
txtEditCountry.Text = "SG";//This is a variable. I give it here for testing purposes
try
{
var web2 = new HtmlWeb();
var doc2 = web2.LoadFromBrowser(url, html =>
{
// WAIT until the dynamic text is set
return !html.Contains("<div id=\"" + taric.ToString() + "\"></div>");
});
//t1 is the data that I cannot get
var t1 = doc2.DocumentNode.SelectSingleNode("//span[contains(text(),'" + txtEditCountry.Text + "')] and .//span[contains(.,'duty_rate')]]").InnerText;
//This is working
var t2 = doc2.DocumentNode.SelectSingleNode("//*[contains(@id,'"+ taric + "')]/table/tbody/tr/td[2]/table/tbody/tr/td[2]").InnerText;
//This is working
var t3 = doc2.DocumentNode.SelectSingleNode("//span[contains(@class,'duty_rate')]").InnerText;
Console.WriteLine("Text 1: " + t1);
Console.WriteLine("Text 2: " + t2);
Console.WriteLine("Text 3: " + t3);
result = new Result
{
Description = t2,
thirdCountryDuty = t3,
tarifPreference = t1
};
return result;
}
catch (Exception ex)
{
result.Description= null;
result.thirdCountryDuty = null;
result.tarifPreference = null;
MessageBox.Show("Check your data and try again \n" + ex.ToString());
return result;
}
}
Данные, которые я не могу получить, это t1, как я написал в коде. Это поле отображается, когда я указываю указанную страну c в URL "& Area = country code". Если я поставлю другую страну, она даст мне другой номер или 0%. Если я ничего не добавлю, он даст мне список всех стран. Если я использую это как Xpath
var t1 = doc2.DocumentNode.SelectSingleNode("//span[contains(text(),'" + txtEditXora.Text + "')]").InnerText;
Возвращает правильную страну, например
Сингапур (SG)
Я хочу указать процентную ставку тарифа для этой страны
Впервые я использую XPath, и я все еще учусь, но я не хочу этого для своего проекта.