 |
| 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
|
|
|
|

August 4th, 2011, 08:57 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
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...
|
|

August 5th, 2011, 03:00 AM
|
|
|
hello im new here!!!
|
|

August 5th, 2011, 03:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 5th, 2011, 05:12 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
but how i get the meta with WebRequest?
i found in google alot of thing but icant get the meta tag...
|
|

August 5th, 2011, 06:27 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 5th, 2011, 09:18 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
how do i make it work
PHP Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles 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
?
|
|

August 6th, 2011, 06:33 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 6th, 2011, 02:15 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
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 
|
|

August 6th, 2011, 02:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 6th, 2011, 02:39 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
thanks alot!!! your more than good book! 
|
|
 |