4
Well, I have a code that reads the page but I need the following:
<a href="/t848p15-teste">2</a>
The idea of the code is to look for a tag <a>
that has this 2
and return the link. In case, it would return: /t848p15-teste
.
The code I have to read is this:
WebRequest request = WebRequest.Create("site_aqui");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
string Texto = reader.ReadToEnd();
It had given an error but it was saying a ". Attributes" in "link". How do I get this only in the first result? He’s picking up on all the results.
– Brunoobarbos
In case you can simply ignore all other results from the list using the LINQ method
FirstOrDefault
for example.– Miguel Angelo
I got the answer... I really needed the
Attributes
=) it was bad!– Miguel Angelo
Can you explain more about this LINQ method? I wanted to get ONLY the '2'.
– Brunoobarbos
LINQ is a set of methods for working with lists.
FirstOrDefault
takes the first element of a list and returns it, or null, if the list is empty.– Miguel Angelo
But I think what you want is not about LINQ... to get the element text,
"2"
, you can use the propertylink.InnerText
.– Miguel Angelo
I tried to use Innertext, but the accents are all buggered with "??", look too much on the internet to try to solve and look like there’s no way. xD
– Brunoobarbos
So I looked for an alternative way to achieve that.
– Brunoobarbos
Here I did not have that accent problem. Try setar Htmldocument encoding:
doc.OptionDefaultStreamEncoding = Encoding.UTF8;
and see if it resolves.– Miguel Angelo