Results 1 to 10 of 10

Thread: Making webbrowser focus on one part of a website

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    103

    Making webbrowser focus on one part of a website

    Hey

    Can anyone tell me / help me find the solution to this:

    Is there anyway i can have a webbrowser only show the top two or three tweets from a twitter account? (https://twitter.com/pewdiepie)
    Like, remove all the other objects on the page, and then center the tweets in the webbrowser?

    Im kinda guessing that without some hardcore coding i will only be able to show ALL the tweets, not just the two or three newest.

    Here is a code i found for hiding website objects from being shown in the browser:
    Code:
    Dim ele = _
                ( _
                    From X In WebBrowser3.Document.GetElementsByTagName("div").Cast(Of HtmlElement)() _
                    Where X.GetAttribute("id") = "[ID OF ELEMENT]" Select X
                ).FirstOrDefault
    
            If ele IsNot Nothing Then
                ele.Style = "Display:none"
            End If
    I don't know how this works, but if there would be any options like replacing
    Code:
    ele.Style = "Display:none"
    with
    Code:
    ele.Style = "Display:only"
    or something like that, to only show the object in question, we would be half way there :P

    Anyone got any ideas? Thanks for all replies. (I apologize for my bad english)

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    103

    Re: Making webbrowser focus on one part of a website

    Anyone? :O

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Making webbrowser focus on one part of a website

    I have to say I can't really see any point to this but I did try a few ideas without success. If you wanted to extract the first few and transfer them to a new page or another control that would probably be possible but if you want to retain the rest of the page then it looks like a bit of a dead end.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    103

    Re: Making webbrowser focus on one part of a website

    Quote Originally Posted by dunfiddlin View Post
    I have to say I can't really see any point to this but I did try a few ideas without success. If you wanted to extract the first few and transfer them to a new page or another control that would probably be possible but if you want to retain the rest of the page then it looks like a bit of a dead end.
    I wouldn't neccesarily need to keep the tweets in the webbrowser. I could just set that to webbrowser.visible = false then have the tweets show up in some other kind of control. (Like putting them in labels.)

    The main point is that i need the two or three (Hopefully three) tweets to show up somewhere so you can easily read it.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Making webbrowser focus on one part of a website

    Ok here you go. The function returns HTML so show the results in a webbrowser (wb1 in this case)

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    4.         wb1.DocumentText = ""
    5.         wb1.Document.Write(Get3Tweets("https://twitter.com/pewdiepie"))
    6.     End Sub
    7.  
    8.     Private Function Get3Tweets(ByVal url As String) As String
    9.         Dim wc As New Net.WebClient
    10.         Dim htm = wc.DownloadString(url)
    11.         Dim wb As New WebBrowser With {.DocumentText = ""}
    12.         wb.Document.Write(htm)
    13.         Dim tweets = From t In wb.Document.GetElementsByTagName("p") Where CType(t, HtmlElement).GetAttribute("classname") = "js-tweet-text"
    14.         Dim s As New System.Text.StringBuilder
    15.         For i = 0 To 2
    16.             s.Append("<p>" & CType(tweets(i), HtmlElement).InnerHtml)
    17.         Next
    18.         wb.Dispose()
    19.         Return s.ToString
    20.     End Function
    21. End Class
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    103

    Re: Making webbrowser focus on one part of a website

    Quote Originally Posted by dunfiddlin View Post
    Ok here you go. The function returns HTML so show the results in a webbrowser (wb1 in this case)
    Well... Ehm... minor problem. (Unrelated to the code you sent me) but im still gonna ask:

    I have two groupboxes that show statistics and ranking. The webbrowser "wb1" is layed on top of those.
    I was planing to hide the groupboxes by "GroupBox1.visible = false" and "GroupBox2.visible = false". And set the webbrowser to visible = true.

    But the webbrowser is apperantly "connected" to the groupboxes as if it is a control within them. And when i hide the groupboxes, the webbrowser doesn't show because of it.

    Can i seperate the webbrowser from the groupboxes somehow? (While having both the groupboxes and the webbrowser at the same location?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    103

    Re: Making webbrowser focus on one part of a website

    Nevermind. Fixed it.
    Used alot of [Name of control].location = New Point(#, #)

  8. #8
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Making webbrowser focus on one part of a website

    I've been trying to adopt dunfiddlin code to be able to get data back from :

    Code:
    <div class="content"> some text <br /></div>
    ...but i'm having a hard time. could someone guide me to the solution?
    Thanks for helping me out.

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Making webbrowser focus on one part of a website

    If you can guide me to the problem!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Making webbrowser focus on one part of a website

    hehe

    well, im trying to get the the "some text" from the
    Code:
    <div class="content"> some text <br /></div>
    i tried changing
    Code:
    ("classname") = "js-tweet-text"
    to
    Code:
    ("classname") = "content"
    but no luck. did other changes to but none seemed to work
    Thanks for helping me out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width