I’m trying to get an image in this page –
http://www.bkstr.com/webapp/wcs/stores/servlet/CourseMaterialsResultsView?catalogId=10001&categoryId=9604&storeId=10161&langId=-1&programId=562&termId=100020629&divisionDisplayName=Stanford&departmentDisplayName=MATH&courseDisplayName=51§ionDisplayName=01&demoKey=d&purpose=browse
I do the normal urllib open stuff (you need to track cookies if anyone’s going to follow along)
and do this
data = soup.findAll("div",{"class":"efMaterialImage left"))
which works fine.
Weirdly, when I do test = data.string, and print the result, console shows ‘None’.
Any idea why?
the
findAllreturns a list of matches, not a single match. A Python list does not have the attribute “string”, however.Try
data[0]instead.Edit:
String only seems to work if the tag has one child and its a string.
<div>something</div>would work, but<div><p>something</p></div>wouldn’t.Use more selectors or use
.contentsinstead.