I’ve been working on a program, but due to Mac OS X’s difficulties in updating python, I’ve been doing it in both 3.2 and 2.6, nevertheless, both versions of the script give me IOErrors (they’re different though). Here’s the script:
This is the 3.2 version:
import sys
import os
import re
import urllib
import urllib.request
## opens the URL as a bytes object
urlfilebytes = urllib.request.urlopen('http://www.reddit.com/r/fffffffuuuuuuuuuuuu')
## saves the bytes object to a string
urlfile = urlfilebytes.read().decode('utf-8'))
## saves list of matches for pattern
matches = re.findall(r'[http://imgur.com/][\s]+"', open(urlfile).read())
This returns the error:
TypeError: invalid file:
The 2.6 version on the other hand:
import sys
import os
import re
import urllib
urlfilebytes = urllib.urlopen('http://www.reddit.com/r/fffffffuuuuuuuuuuuu')
urlfile = urlfilebytes.read().decode('utf-8')
matches = re.findall(r'[http://imgur.com/][\s]+"', open(urlfile).read())
This returns the error:
IOError: [Errno 63] File name too long: u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" ><head><title>FFFFFFFUUUUUUUUUUUU-</title><meta name="keywords" content=" r **ETC ETC ETC**
I’m kind of stumped here, can anyone help me out?
Are you sure you don’t want to just do this?
And I bet the regexp doesn’t do what you think it does. Perhaps you need to ask another question about that
Perhaps something like this
or this