How to read the external page title?

I think this is possible with jQuery, but any ASP.NET server code is good for my situation.

With jQuery, I can load a page, for example, into a div, and filter out the div for the tag <title>, but I think it is not good for heavy pages to read all the content first and then read the title tag .. or maybe this is a very simple solution? In any case, I could not find anything about it from the Internet. thanks

+3
source share
7 answers

Ok thanks to cjjer and Boo, I just read more about regex, and finally the code works for me.

Dim qq As New System.Net.WebClient
    Dim theuri As New Uri(TextBox1.Text)
    Dim res As String = qq.DownloadString(theuri)
    Dim re As Regex = New Regex("<title\b[^>]*>(.*?)</title>", RegexOptions.Singleline)
    Dim ma As Match = re.Match(res)


    If Not ma Is Nothing And ma.Success Then
        Response.Write(ma.Groups(1).Value.ToString())
    Else
        Response.Write("error")
    End If

, , - 2 3 , , , : | ?

+2

cjjer .

: <title>(?<Content>.*?)?</title>

-, ( , URI ).

Match tMatch = new RegEx(@"<title>(?<Content>.*?)?</title>").Match(new System.Net.WebClient().DownloadString(url));

if ((null != tMatch) && (tMatch.IsSuccess)) {
    //  yay.
    title = tMatch.Groups("Content").value;
}
+2

, 1KiB , ( , ), .

+1

, - , ... (asp.net, php,...) -. - , .

0

. WebClient .

, , , , . , , , , , .

0
string title=Regex.Match(new System.Net.WebClient().DownloadString(url),(@"<title>(.*?)</title>"))[0].Groups[1].ToString();

try.i .

0

, .
.,


char[] data = new char[299];
System.Net.HttpWebRequest wr =(HttpWebRequest)WebRequest.Create("http://www.yahoo.com");
wr.AddRange("bytes", 0, 299);
HttpWebResponse wre = (HttpWebResponse)wr.GetResponse();
StreamReader sr = new StreamReader(wre.GetResponseStream());
sr.Read(data, 0, 299);
Console.WriteLine((data));
sr.Close();

EDIT: , , . fiddler, .

EDIT2: , .

0

Source: https://habr.com/ru/post/1704019/


All Articles