Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#XPath获取InnerText的值_C#_Html_Xpath - Fatal编程技术网

c#XPath获取InnerText的值

c#XPath获取InnerText的值,c#,html,xpath,C#,Html,Xpath,我有如下html文本: <div class="Lts(1px) Fz(14px) Fs(i) Lh(2.5) Fw(300) Tsh($temperature-text-shadow)"><span>5/3, 12:48 PM</span></div></section><section class="weather-card C(#fff) M(10px) Pos(a) B(0) Start(0) End(0)" data-t

我有如下html文本:

<div class="Lts(1px) Fz(14px) Fs(i) Lh(2.5) Fw(300) Tsh($temperature-text-shadow)"><span>5/3, 12:48 PM</span></div></section><section class="weather-card C(#fff) M(10px) Pos(a) B(0) Start(0) End(0)" data-type="temperature" data-reactid="21"><div class="temperature Fz(14px) Tsh($temperature-text-shadow)" data-reactid="22"><div class="My(2px)" data-reactid="23"><span data-code="30" class="Va(m)" data-reactid="24"><img alt="Partly Cloudy" title="Partly Cloudy" class=" " src="Sadiqabad,%20Pakistan%20-%20Weather%20Forecasts%20%20%20Maps%20%20%20News%20-%20Yahoo%20Weather_files/partly_cloudy_day2x.png" data-reactid="25" width="32" height="32"></s`enter code here`pan><span class="description Va(m) Px(2px) Fz(1.3em)--sm Fz(1.6em)" data-reactid="26">Partly Cloudy</span></div>
除了updatetime之外,它对所有人都有效,但它的工作原理是:

WindowsFormsApplication26.exe中的System.NullReferenceException


请帮助获取value updatetime变量。

不要使用浏览器工具生成的XPath-它非常不可靠,绝对不可读。谢谢编辑。。
HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument doc = web.Load("https://www.yahoo.com/news/weather/pakistan/punjab/sadiqabad-2211402");
                var xpathcity = "//*[@id=\"Lead-1-WeatherLocationAndTemperature\"]/div/section[1]/div[1]/div/h1";
                var xpathcountry = "/html/body/div[1]/div/div[1]/div/div[4]/div[1]/div/div[2]/div/div/div/div/section[1]/div[1]/div/div";
                var xpathupdatetime = "//*[@id=\"Lead-1-WeatherLocationAndTemperature\"]/div/section[1]/div[3]/span";
                var xpathcloudname = "//*[@id=\"Lead-1-WeatherLocationAndTemperature\"]/div/section[2]/div/div[1]/span[2]";
                var xpathtemperature = "/html/body/div[1]/div/div[1]/div/div[4]/div[1]/div/div[2]/div/div/div/div/section[2]/div/div[3]/span[1]";
                textBox1.Text = doc.DocumentNode.SelectSingleNode(xpathcity).InnerText;
                textBox2.Text = doc.DocumentNode.SelectSingleNode(xpathcountry).InnerText.Trim ();
              **// Console.WriteLine ( doc.DocumentNode.SelectSingleNode(xpathupdatetime).InnerText);**
                textBox4.Text = doc.DocumentNode.SelectSingleNode(xpathcloudname).InnerText;
                textBox5.Text = doc.DocumentNode.SelectSingleNode(xpathtemperature).InnerText;