Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Extracting text from a webpage

    Hi,

    I am using the following VBA code to extract text from a webpage

    I am interested in the text inside a node called SPAN. As there are some unwanted SPAN nodes, I am trying to differentiate them on the basis of their font type, but I am getting an error at hinput.font = ”verdana” (run time error 438).
    What property can I use to differntiate the SPAN nodes?

    Code:
    VBA code
    …
    
    Set hdoc = IE.document
    
    Set hColl = hdoc.getElementsByTagName("SPAN")
    
    For Each hinput In hColl
    
    If hinput.font = ”verdana” then
    
    MsgBox hinput.innertext
    …
    Next
    Code:
    HTML source code 
    
    <span style='font:normal 12px verdana;color:#000000;'>Dad: Ess Baar exam me paas ho<br>ya fail BIKE zarur dilaunga.<br>Son: Kaunsi bike?<br>Dad: Pass he to “APACHE” college<br>jane ke liye.<br>Fail hue to “RAJDOOT” dood<br>bechne ke liye...</span>


    Thanks,

    MG.
    Last edited by musicgold; 11-07-2010 at 04:24 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    use the
    Code:
    <span id=" ">
    this will put each one as a specific span.

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey Chris,

    Thanks. Where do I get the id? If you look at the source code of the webpage, there are no IDs for the SPANs.

  • #4
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    So it is not your source code??

  • #5
    New Coder
    Join Date
    Oct 2008
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts
    No. It is not my website. I am just trying to extract some text from the site.

    http://www.frendz4m.com/p/forum/show...D=0&ID=2066722

  • #6
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Ripping content from that website may be against its terms of use. Please check back on us when you have checked that this is not the case.

  • #7
    New Coder
    Join Date
    Oct 2008
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ripping content from that website may be against its terms of use. Please check back on us when you have checked that this is not the case
    Hmm. Well I am not ripping the website. I just need to copy certain jokes from the website. The website doesn't say that users shouldn't copy contents from its pages. I am able to copy jokes from the site even without being a member.
    I thought a vba macro I could save me some time.


  •  

    Posting Permissions

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