python - AttributeError: 'NoneType' object has no attribute 'find' -
python - AttributeError: 'NoneType' object has no attribute 'find' -
i have set of urls,i have urls in list called list(eg http://www.amazon.com/b/ref=s9_al_bw_brwse_a_v?_encoding=utf8&node=9097393011&pf_rd_m=atvpdkikx0der&pf_rd_s=center-4&pf_rd_r=10rxcp9tzpw3bp73ekha&pf_rd_t=101&pf_rd_p=1818119462&pf_rd_i=2858778011
). @ bottom of urls page there number of pages each category.
there span element trying homecoming url.but returning nonetype error
the code have tried far
for links in full_links: mech=browser() mech.set_handle_robots(false) mech.addheaders = [('user-agent', 'mozilla/5.0 (x11; u; linux i686; en-us; rv:1.9.0.1) gecko/2008071615 fedora/3.0.1-1.fc9 firefox/3.0.1')] url=links page=mech.open(url) html=page.read() soup=beautifulsoup(html) no_pages = soup.find('div',id="pagn") a=no_pages.find('span',{'class':'pagnlink'}) aes in a: print aes.text in elm.findall('a'): link='http://www.amazon.com'+a['href'] print link
you failed include total traceback, presumably soup.find('div')
phone call returned none
. that page element tried find not present.
if element not found, element.find()
returns none
, , subsequent line tries utilize none
value fail. in case no_pages
none
, no_pages.find()
fails.
for element searches these, much easier utilize css selectors:
for page_link in soup.select('div#pagn span.pagnlink a[href]'): link = 'http://www.amazon.com' + page_link['href'] print link
this find links within <div id="pagn">
-> <span class="pagnlink>
element tree, provided have href
attribute.
this search homecoming empty loop if either div
or span
not present.
python beautifulsoup
Comments
Post a Comment