#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0

    Need to print a line of html source


    Iv been fluent in python for a few years, C++ more recently.

    I have a script that will view the source of an html webpage, now I need to have python only print out the lines of html that contain a certain word.

    What I have at the moment is.

    import urllib
    f = urllib.urlopen("web address")
    print f.read()
    Im not sure if this is a move in the right direction but i also had this.

    import urllib
    f = urllib.urlopen("web address")
    line = "embed"
    print line in f.read()
    But this just tells me if the specified word/phrase is in the source.


    I hope I was specific enough

    CP of DC949
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Untested, but I guess it works:
    Python Code:
    import urllib
    f = urllib.urlopen("web address")
    word = "embed"
    for line in f:
        if word in line:
            print line


    Regards, mawe
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0
    Originally Posted by mawe
    Hi!

    Untested, but I guess it works:
    Python Code:
    import urllib
    f = urllib.urlopen("web address")
    word = "embed"
    for line in f:
        if word in line:
            print line


    Regards, mawe
    Thanks so much man, Iv been stressing on that all day. And thanks for the quik reply.

    CP of DC949

IMN logo majestic logo threadwatch logo seochat tools logo