I'm a python/coding newbie and I'm trying to put a two for loops into a while loop? Can I do this? How can I print out the dictionary mydict to make sure I am doing this correctly?
I'm stuck.
40 minutes later. Not stuck anymore. Thanks everyone!
def runloop():
while uid<uidend:
for row in soup.findAll('h1'):
try:
name = row.findAll(text = True)
name = ''.join(name)
name = name.encode('ascii','ignore')
name = name.strip()
mydict['Name'] = name
except Exception:
continue
for row in soup.findAll('div', {'class':'profile-row clearfix'}):
try:
field = row.find('div', {'class':'profile-row-header'}).findAll$
field = ''.join(field)
field = field.encode('ascii','ignore')
field = field.strip()
except Exception:
continue
try:
value = row.find('div', {'class':'profile-information'}).findAl$
value = ''.join(value)
value = value.encode('ascii','ignore')
value = value.strip()
return mydict
mydict[field] = value
print mydict
except Exception:
continue
uid = uid + 1
runloop()
from pprint import pprintthenpprint(your_dict). You can read up about python's pretty printer if you want to know more about it.prints to see if the code actually does what you expect. Remove theexceptions or make them informative by rewriting them as @gnibbler told you below. If you want to be sure sure go step by step: Uncomment all your code. Add just rudimentary code line by line and run your program after each litle change and observe how theprints change (or change not) too until you got what you want.