F
F
FaNaT2018-04-12 00:04:15
Parsing
FaNaT, 2018-04-12 00:04:15

How to exclude class from xpath query in C#?

Hello.
There are such xpath queries:

outputHtml = HD.DocumentNode.SelectNodes("//div[@class='reader-text font-size-medium']");
outputHtml = HD.DocumentNode.SelectNodes("//div[@style='display: block; text-align: justify; margin-bottom: 12px;']");

They get the content of the div, but it also includes this construct:
<div class="reader-pagination"><a class="pull-left chapter-btn" id="link-left" href="/reader/ne-princ-no-soidesh-b34996?c=276330">Пред. часть</a><div class="col-xs-offset-4 pag-center"><span class="current">1</span><a onclick="Reader.goTo(2)">2</a><span class="dots">...</span><a class="first" onclick="Reader.goTo(4)">4</a></div><a class="pull-right" id="link-right" onclick="Reader.goTo(2)"><i class="glyphicon glyphicon-chevron-right"></i> Вперед</a><div class="clearfix"></div></div>

Here I need to do something so that the contents of the div with the reader-pagination class do not fall into those two requests that are above.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2018-06-21
@Roman-Fov

It is difficult to answer this question without a full document and a more accurate understanding of the problem. You can select everything except a certain element by excluding it in the xpath.
Those change the principle of document processing. Process not the element element1 itself, but all child elements to element1.
Let's say we have a document:

<root>
<elem attr="a">a</elem>
<elem attr="b">b</elem>
<elem attr="c">c</elem>
</root>

According to requests, I see you are trying to do something like this (select everything that is in the element):
And get the text:
<root>
<elem attr="a">a</elem>
<elem attr="b">b</elem>
<elem attr="c">c</elem>
</root>

But you can only select content + by imposing certain restrictions:
Result:
<elem attr="a">a</elem>
<elem attr="c">c</elem>

This will make it easier to work with.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question