Page 3 of 14 FirstFirst 1234513 ... LastLast
Results 21 to 30 of 138

Thread: [Beginner] Programming Challenge: 4

  1. #21
    Join Date
    Sep 2007
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 4

    That's not arabic ^

  2. #22
    Join Date
    Dec 2006
    Location
    Birmingham, England
    Beans
    83
    Distro
    Ubuntu 6.06 Dapper

    Re: [Beginner] Programming Challenge: 4

    My entry:
    Code:
    #!/usr/bin/env python
    
    import urllib
    import re
    
    t = re.compile('<title>(.*)</title>')
    url = raw_input('What page do you wish to copy?\n')
    index = urllib.urlopen(str(url)).read()
    title = t.search(index).group(1)
    f = open(str(title), 'w')
    f.write(index)
    f.close()
    print 'Saved as %s .xhtml' % (title)

  3. #23
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 4

    Quote Originally Posted by Kadrus View Post
    That's not arabic ^
    ur right...missed that...Chinese?

  4. #24
    Join Date
    Sep 2007
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 4

    Not really,Hindi if I am not mistaken.I know arabic so I would have known..
    http://en.wikipedia.org/wiki/Hindi

  5. #25
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 4

    ur right thanks

  6. #26
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 4

    Quote Originally Posted by LaRoza View Post
    You will have to do the following:

    • Write a program that will read a webpage and puts its text into a file named "index.xhtml"
    • The test site will be: http://laroza.freehostia.com/home/index.php
    • That is the bare minimum requirements, but I would ask you try to make it work for any site.


    You do NOT have to:

    • Have it do anything but download the single file of a web page, so ignore any external scripts or css.
    • Have it to any rendering, just write it to a file (for opening with a browser, most likely)


    For extra credit:

    • Have either prompt or use a command line argument to do do this with any webpage
    • Have it name the output file after the title of the document (hint: text in the elements <title></title>, you can use xml or html parsers for this, or you can use regular expressions)


    The test page is valid XHTML 1.1 (and is valid XML). All conditions and extra credit can be done with standard Python. If you use another language or non standard libs, let me know exactly how to get your entry working.



    Rules:
    Do not copy code, but you can obviously read it

    Try not to comment on other submissions. It will be hard to judge changing entries. If you edit your code, post the new version and make it clear there is a new code.
    ok a few questions
    • 1. can you explain the render thing better...i don't get that but i found a good example on the web that taught me how to do this challenge but has poor documentation and mentions something about renders in the comments
    • 2. is it just me or are the forum tags the same has html/xhtml tags but with [] brackets instead of <> ones

  7. #27
    Join Date
    Mar 2008
    Beans
    1,755

    Re: [Beginner] Programming Challenge: 4

    2. is it just me or are the forum tags the same has html/xhtml tags but with [] brackets instead of <> ones
    This is more or less true but HTML has a lot more tags than BBC (forum) code has.

  8. #28
    Join Date
    Oct 2007
    Beans
    410

    Re: [Beginner] Programming Challenge: 4

    always wanted to do this in perl,
    here's mine:

    Code:
    ## Ubuntu Challenge #4, written by Badperson 8/14/08 
    ## this script will default to look for http://laroza.freehostia.com/home/index.php, 
    ## but will accept an arugument for a url
    use LWP::Simple;
    use strict;
    use warnings;
    
    
    my $url;
    
    
    if (@ARGV == 1 ){
    $url = $ARGV[0];
    } else {
    $url = "http://laroza.freehostia.com/home/index.php";
    
    }
    
    my $content = get($url) or die "can't read $url $!\n";
    
    open(OUT, ">index.xhtml");
    print OUT '<!-- Ubuntu Challenge #4, written by Badperson 8/14/08 -->';
    print OUT '<!-- searching for url: $url -->';
    print $content;
    print OUT $content;
    
    print "\n\nScript done. \n";

  9. #29
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 4

    also does the program have to load it or just save it to a xhtml file

  10. #30
    Join Date
    Jun 2008
    Location
    California, USA
    Beans
    1,030
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 4

    OK, I thought this was the perfect opportunity to practice the PyQt that I was learning, so I created both a CLI version and a GUI version, for the GUI version you need to have Qt4 and PyQt4 both installed.

    The CLI version:
    PHP Code:
    import urllib2

    class WebsiteCopier(object):
        
        
    def SaveWebsite(self):
            try:
                
    websiteChoice raw_input("What website would you like to copy?: ")
                
    website urllib2.urlopen(str(websiteChoice)).read()
                
    fileTitle website.split("<title>")[1].split("</title>")[0] + ".xhtml"
                
    websiteFile open(fileTitle"w")
                
    websiteFile.writelines(website)
                print 
    "Successfully completed copying website to " fileTitle "!"
            
    except:
                print 
    "Error in downloading or writing website to file."
            
    finally:
                
    websiteFile.close()

    if 
    __name__ == "__main__":
        
    WebsiteCopier WebsiteCopier()
        
    WebsiteCopier.SaveWebsite() 
    The GUI Version:
    PHP Code:
    import sys
    import urllib2
    from PyQt4
    .QtCore import *
    from PyQt4.QtGui import *

    class 
    WebsiteForm(QDialog):
        
        
    def __init__(selfparent=None):
            
    super(WebsiteForm,self).__init__(parent)
            
            
    self.WebsiteLine QLineEdit("Type a website URL here.")
            
    self.WebsiteLine.selectAll()
            
            
    self.browser QTextBrowser()
            
            
    grid QGridLayout()
            
    grid.addWidget(self.WebsiteLine00)
            
    grid.addWidget(self.browser10)
            
    self.setLayout(grid)
            
    self.setWindowTitle("Website Copier")
            
            
    self.connect(self.WebsiteLineSIGNAL("returnPressed()"), self.updateUi)
            
        
    def updateUi(self):
            try:
                
    text self.WebsiteLine.text()
                
    website urllib2.urlopen(str(text)).read()
                
    fileTitle website.split("<title>")[1].split("</title>")[0] + ".xhtml"
                
    websiteFile open(fileTitle"w")
                
    websiteFile.writelines(website)
                
    self.browser.append("<b>Successfully finished saving website to %s!</b>" fileTitle)
            
    except:
                
    self.browser.append("<font color=red>%s is an invalid website URL!</font>" text)
            
    finally:
                
    websiteFile.close()
                
    app QApplication(sys.argv)
    form WebsiteForm()
    form.show()
    app.exec_() 
    Suggesstions, etc... are welcomed

    Cheers
    Last edited by OutOfReach; August 14th, 2008 at 09:49 PM.

    Blog | I'm available for programming contributions. C & Python.
    Intel Core i7 920 | EVGA x58 SLI | NVidia GeForce 8600 GT | WD 500GB HDD | Corsair XMS3 3GB | Ubuntu 9.04

Page 3 of 14 FirstFirst 1234513 ... LastLast

Bookmarks

Posting Permissions

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