Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2011, 08:57 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default how to i get other web meta tags?

somebody know how?

i mean that i have textbox and button,and for the example textbox.text=http://google.com and then the press button recall from google the meta tags.. like descrption and title...
 
Old August 5th, 2011, 03:00 AM
irishelnsman928
Guest
 
Posts: n/a
Default hello im new here!!!

pole fitness denver - pole dancing denver - laser back surgery
Received Infraction
 
Old August 5th, 2011, 03:54 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use the WebRequest class to request the page and then retrieve its HTML. You can then parse the HTML for the requestes meta tags. For that you could use the HTML Agility Pack: http://htmlagilitypack.codeplex.com/

For both techniques you'll find plenty of examples on Google.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
nir987 (August 5th, 2011)
 
Old August 5th, 2011, 05:12 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

but how i get the meta with WebRequest?
i found in google alot of thing but icant get the meta tag...
 
Old August 5th, 2011, 06:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Take a look here: http://www.google.com/#sclient=psy&h...ack++find+meta

The first result is a SO post with sample code, but there are many more examples available.

Cheers,
Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
nir987 (August 5th, 2011)
 
Old August 5th, 2011, 09:18 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

how do i make it work
PHP Code:
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load

        Dim doc 
As New HtmlDocument
        doc
.LoadHtml("http://p2p.wrox.com")
        
Dim node As HtmlNode doc.DocumentNode.SelectSingleNode("//meta[@name='description']")



        If 
node.ToString Not Nothing Then
            Dim str 
As String node.GetAttributeValue("content""")


        
End If

    
End Sub 

?
 
Old August 6th, 2011, 06:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you read the documentation that comes with the HTML Agility Pack? LoadHtml expects an HTML string, not a Web URL.

As hinted in my first reply, you need to use WebRequest to request the page, grab its HTML and feed that to LoadHtml.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 6th, 2011, 02:15 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

PHP Code:
       Dim URL As String "http://www.youtube.com/watch?v=66rY3wHSneA"
        
Dim request As WebRequest WebRequest.Create(URL)
        
Dim response1 As WebResponse request.GetResponse()
        
Dim reader As StreamReader = New StreamReader(response1.GetResponseStream())
        
Dim str As String reader.ReadLine()

        
Response.Write(str
its write nothing...so i can grab it to loadhtml..
what could be the problem?
i think this is my last issue
 
Old August 6th, 2011, 02:29 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

ReadLine works for me with your code and returns the doc type. However, you probably want to use ReadToEnd to grab the full HTML. The following works for me and assigns str the meta tag. Notice I also added some Using statements to ensure objects are cleaned up.

Code:
Dim url As String = "http://www.youtube.com/watch?v=66rY3wHSneA"
Dim request As WebRequest = WebRequest.Create(url)
Using response As WebResponse = request.GetResponse()
  Using reader As StreamReader = New StreamReader(response.GetResponseStream())
    Dim result As String = reader.ReadToEnd()
    Dim doc As New HtmlDocument()
    doc.LoadHtml(result)
    Dim node As HtmlNode = doc.DocumentNode.SelectSingleNode("//meta[@name='description']")
    If node.ToString IsNot Nothing Then
      Dim str As String = node.GetAttributeValue("content", "")
    End If
  End Using
End Using
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
nir987 (August 6th, 2011)
 
Old August 6th, 2011, 02:39 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

thanks alot!!! your more than good book!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using meta tags amatytfc ASP.NET 2.0 Basics 1 August 6th, 2007 05:47 PM
meta tags ferlach HTML Code Clinic 5 June 5th, 2007 04:17 PM
META tags and master pages thenoseknows ASP.NET 2.0 Professional 1 October 9th, 2006 01:02 PM
MasterPages ContentPages and Meta tags michaelcode ASP.NET 2.0 Basics 5 June 1st, 2006 04:13 PM
Meta tags Adam H-W HTML Code Clinic 2 November 19th, 2003 11:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.