Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39421

Re: Urllib's urlopen and urlretrieve

References <34998ea2-6b19-4a98-8ea0-389aca0192ca@googlegroups.com>
From Michael Herman <hermanmu@gmail.com>
Date 2013-02-21 04:59 -0800
Subject Re: Urllib's urlopen and urlretrieve
Newsgroups comp.lang.python
Message-ID <mailman.2162.1361451589.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Are you just trying to get the html? If so, you can use this code-

*import urllib*
*
*
*# fetch the and download a webpage, nameing it test.html*
*urllib.urlretrieve("http://www.web2py.com/", filename="test.html")*


I recommend using the requests library, as it's easier to use and more
powerful:

*import requests*

*# retrive the webpage
r = requests.get("http://www.web2py.com/")*

*# write the content to test_request.html
with open("test_requests.html", "wb") as code:
*

*code.write(r.content)*


If you want to get up to speed quickly on internet programming, I have a
course I am developing. It's on kickstarter - http://kck.st/VQj8hq. The
first section of the book dives into web fundamentals and internet
programming.


On Thu, Feb 21, 2013 at 4:12 AM, <qoresucks@gmail.com> wrote:

> I only just started Python and given that I know nothing about network
> programming or internet programming of any kind really, I thought it would
> be interesting to try write something that could create an archive of a
> website for myself. With this I started trying to use the urllib library,
> however I am having a problem understanding why certain things wont work
> with the urllib.urlretrieve and urllib.urlopen then reading.
>
> Why is it that when using urllib.urlopen then reading or
> urllib.urlretrieve, does it only give me parts of the sites, loosing the
> formatting, images, etc...? How can I get around this?
>
> Lastly, while its a bit off topic, I lack a good understanding of network
> programming as a whole. From making programs communicate or to simply
> extract data from URL's, I don't know where to even begin, which has lead
> me to learning python to better understand it hopefully then carry it over
> to other languages I know. Can anyone give me some advice on where to begin
> learning this information? Even if its in another language.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Urllib's urlopen and urlretrieve qoresucks@gmail.com - 2013-02-21 04:12 -0800
  Re: Urllib's urlopen and urlretrieve Michael Herman <hermanmu@gmail.com> - 2013-02-21 04:59 -0800
    Re: Urllib's urlopen and urlretrieve qoresucks@gmail.com - 2013-02-21 21:09 -0800
      Re: Urllib's urlopen and urlretrieve Dave Angel <davea@davea.name> - 2013-02-22 12:05 -0500
      Re: Urllib's urlopen and urlretrieve MRAB <python@mrabarnett.plus.com> - 2013-02-22 17:18 +0000
    Re: Urllib's urlopen and urlretrieve qoresucks@gmail.com - 2013-02-21 21:09 -0800
  Re: Urllib's urlopen and urlretrieve Dave Angel <davea@davea.name> - 2013-02-21 10:56 -0500
  Re: Urllib's urlopen and urlretrieve rh <richard_hubbe11@lavabit.com> - 2013-02-21 09:47 -0800
  Re: Urllib's urlopen and urlretrieve rh <richard_hubbe11@lavabit.com> - 2013-02-21 09:55 -0800
  Re: Urllib's urlopen and urlretrieve Dave Angel <davea@davea.name> - 2013-02-21 13:04 -0500
  Re: Urllib's urlopen and urlretrieve Dave Angel <davea@davea.name> - 2013-02-21 13:53 -0500

csiph-web