我附加了一张图片,想要在C#中使用Linq到XML扩展<div> .... </div>
。我试过这种方式,但无法解决它。
XDocument.Parse(content); // this is Linq to XML
XElement root = XElement.Load(url);
IEnumerable<XElement> tests =
from el in root.Elements("Div")
where (string)el.Element("Confused") == "Confused"
select e
foreach (XElement el in tests)
Console.WriteLine((string)el.Attribute("Confused"));
如果有任何简单的方法从使用任何其他技术(包括 XmlDocument,XmlPullParser或LinqToXml )的具有此类结构的网页中提取内容,我将不胜感激。 谢谢。
按要求编辑:
<div class="story-body__inner" property="articleBody">
<figure class="media-landscape has-caption full-width lead">
<span class="image-and-copyright-container">
<img class="js-image-replace" alt="US President Donald Trump arrives to speak at a "Make America Great Again" rally in Phoenix, Arizona, on August 22, 2017" src="https://ichef-1.bbci.co.uk/news/660/cpsprodpb/5256/production/_97487012_ad54fff5-3ff7-41ec-9e30-c239de238cc4.jpg" width="976" height="549" data-highest-encountered-width="660">
<span class="off-screen">Image copyright</span>
<span class="story-image-copyright">AFP</span>
</span>
<figcaption class="media-caption">
<span class="off-screen">Image caption</span>
<span class="media-caption__text">
Donald Trump touched on immigration, healthcare and his enemies during the Arizona rally
</span>
</figcaption>
</figure><p class="story-body__introduction">Donald Trump has vowed to close down the government if necessary to build his wall along the Mexico border.</p><p>The US president told supporters at a "Make America Great Again" rally in Phoenix, Arizona, that the opposition Democrats were being "obstructionist".</p><p>During the 80-minute speech, he also took aim at the media, blaming them for giving far right groups "a platform".</p><p>But he selectively quoted his initial response to violence at a far-right rally that left one woman dead.</p><p>He omitted the controversial claim that <a href="http://www.bbc.co.uk/news/world-us-canada-40943425" class="story-body__link">"many sides" had to shoulder the blame</a> for violence in Charlottesville, Virginia.</p><div id="bbccom_mpu_1_2_3" class="bbccom_slot mpu-ad" aria-hidden="true">
<div class="bbccom_advert">
<script type="text/javascript">
/**/
(function() {
if (window.bbcdotcom && bbcdotcom.adverts && bbcdotcom.adverts.slotAsync) {
bbcdotcom.adverts.slotAsync('mpu', [1,2,3]);
}
})();
/**/
</script>
</div>
</div><p>In his wide-ranging speech, Mr Trump also said he thought he would "probably end up terminating Nafta", the trade deal with Mexico and Canada.</p><p>On North Korea, the president sounded a hopeful note about the possibility of a reduction in tensions over Pyongyang's missile tests and nuclear programme.</p><p>Referring to North Korean leader Kim Jong-un, Mr Trump said: "I respect the fact that he is starting to respect us".</p><p>"And maybe - probably not, but maybe - something positive can come about," he added.</p><ul class="story-body__unordered-list">
<li class="story-body__list-item"><a href="http://www.bbc.co.uk/news/world-us-canada-40948812" class="story-body__link">Charlottesville: What made Trump remarks so offensive?</a></li>
<li class="story-body__list-item"><a href="http://www.bbc.co.uk/news/world-us-canada-40946386" class="story-body__link">Bush presidents wade into Trump furore </a></li>
<li class="story-body__list-item"><a href="http://www.bbc.co.uk/news/business-40943041" class="story-body__link">Nafta: What is at stake?</a></li>
</ul><p>But while his comments were met with cheers inside the conference centre, anti-Trump protesters who had gathered outside the rally clashed with police after the rally had finished.</p><p>Police deployed tear gas after the protesters threw bottles and rocks, Reuters news agency reported.</p><figure class="media-landscape has-caption full-width">
<span class="image-and-copyright-container">
<img src="https://ichef.bbci.co.uk/news/624/cpsprodpb/A076/production/_97487014_7815d739-c520-4475-a24d-8f5ccfcca705.jpg" datasrc="https://ichef.bbci.co.uk/news/320/cpsprodpb/A076/production/_97487014_7815d739-c520-4475-a24d-8f5ccfcca705.jpg" class="responsive-image__img js-image-replace" alt="Large inflated figures of Sheriff Joe Arpaio and President Trump are seen above ant-Trump protesters outside the Phoenix Convention Center" width="976" height="549" data-highest-encountered-width="624">
<span class="off-screen">Image copyright</span>
<span class="story-image-copyright">Getty Images</span>
</span>
<figcaption class="media-caption">
<span class="off-screen">Image caption</span>
<span class="media-caption__text">
Protesters hold up an inflatable Joe Arpaio, whom Mr Trump hinted he would pardon
</span>
</figcaption>
</figure><p>President Trump began and finished his speech by urging the American people to come together.</p><p>But he quickly turned on familiar foes, beginning with the media, which he said had misrepresented his "perfect" words in the wake of the violence in Charlottesville, where Heather Heyer was killed after a car ploughed into a crowd of people protesting against far-right demonstrators including neo-Nazis.</p><p>He accused "truly dishonest people in the media and the fake media" of "trying to take away our history and heritage" because, he said, they "don't like our country".</p><p>He quoted his own initial public response to what happened in Charlottesville.</p><p>"This is what I said on Saturday: 'We're closely following the terrible events unfolding in Charlottesville, Virginia,' - this is me speaking. 'We condemn in the strongest possible terms this egregious display of hatred, bigotry and violence.' That's me speaking on Saturday, right after the event," he said.</p><p>But what he actually said on 12 August was: "We condemn in the strongest possible terms this egregious display of hatred, bigotry and violence on many sides, on many sides."</p><p>Mr Trump's attention then turned to immigration, and to the Democrats who he said were "putting all of America's safety at risk" by opposing the wall he wants to build along the US's southern border with Mexico.</p><ul class="story-body__unordered-list"><li class="story-body__list-item"><a href="http://www.bbc.co.uk/news/resources/idt-d60acebe-2076-4bab-90b4-0e9a5f62ab12" class="story-body__link">Six things that could topple Trump's wall</a></li></ul><p>He said immigration officers who worked in the area said it was "vital" to stem the flow of illegal immigrants.</p><p>Mr Trump concluded: "If we have to close down government, we are building that wall."</p><p>Mr Trump also used the rally to hint he would pardon controversial former Arizona sheriff Joe Arpaio, a man who rose to national prominence because of his tough stance against illegal immigration.</p><figure class="media-landscape has-caption full-width">
<span class="image-and-copyright-container">
<img src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" datasrc="https://ichef-1.bbci.co.uk/news/320/cpsprodpb/EE96/production/_97487016_3eff3038-16fe-4f5a-963a-b36339e3320e.jpg" class="responsive-image__img responsive-image__img--loading js-image-replace" alt="Supporters of U.S. President Donald Trump cheer him at a campaign rally in Phoenix, Arizona, U.S., August 22, 2017." width="976" height="549">
<span class="off-screen">Image copyright</span>
<span class="story-image-copyright">Reuters</span>
</span>
<figcaption class="media-caption">
<span class="off-screen">Image caption</span>
<span class="media-caption__text">
Supporters could be heard to chant "CNN sucks" during the rally
</span>
</figcaption>
</figure><p>He told the crowd Mr Arpaio - who was <a href="http://www.bbc.co.uk/news/world-us-canada-40780659" class="story-body__link">found guilty of criminal contempt</a> in July - "is going to be just fine", but would not formally pardon him at the moment because "I don't want to cause any controversy".</p><p>His comments directly contradicted those of White House spokeswoman Sarah Sanders, who said on Tuesday "there will be no discussion of that today".</p><p>Mr Arpaio, 85, was found to have violated a judge's 2001 order that he cease detaining migrants who are not suspected of having committed a state crime.</p>
</div>