import re import string import shutil import os import os.path import time import datetime import math import urllib array import array import random filehandle = urllib.urlopen('http://www.google.com/') #open webpage s = filehandle.read() #read print s #display #what plan once first part working #results = re.findall('[<td style="font-weight:bold;" nowrap>$][0-9][0-9][0-9][.][0-9][0-9][</td></tr></tfoot></table>]',s) #earnings = '$ ' #for money in results: #earnings = earnings + money[1]+money[2]+money[3]+'.'+money[5]+money[6] #print earnings #raw_input()
this code have far. have looked @ other forums give solutions such name of script, parse_money.py, , have tried doing urllib.request.urlopen , have tried running on python 2.5, 2.6, , 2.7. if has suggestions welcome, everyone!! --matt
---edit--- tried code , worked, im thinking kind of syntax error, if sharp eye can point out, appreciative.
import shutil import os import os.path import time import datetime import math import urllib array import array import random b = 3 #find url url = raw_input('type url read from[example: http://www.google.com/] :') while b == 3: #get file name file1 = raw_input('enter file name downloaded code:') filepath = file1 + '.txt' if os.path.isfile(filepath): print 'file exists' b = 3 else: print 'filename accepted' b = 4 file_path = filepath #open file filewrite = open(file_path, 'a') #acces url filehandle = urllib.urlopen(url) #display souce code lines in filehandle.readlines(): filewrite.write(lines) print lines print 'the above has been saved in both text , html file' #close files filehandle.close() filewrite.close()
it appears urlopen
method available in urllib.request
module , not in urllib
module you're expecting.
rule of thumb - if you're getting attributeerror
, field/operation not present in particular module.
edit - andidog pointing out - solution valid py 3.x, , not applicable py2.x!
Comments
Post a Comment