Python Forum
Web scraping error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Web scraping error (/thread-25182.html)



Web scraping error - jithin123 - Mar-22-2020

AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?

what is this error?

My code given below

while True:
    response= requests.get(url)
    response    
    data=response.text
    soup= BeautifulSoup(data,'html.parser') 
    apis=soup.find_all('tr',{"class":"odd views-row-first"})

    for api in apis:
        name= apis.find('td',{"class":"views-field views-field-pw-version-title"}).text
        des=apis.find('td',{'class':'views-field views-field-search-api-excerpt views-field-field-api-description hidden-xs visible-md visible-sm col-md-8'}).text
        category=apis.find('td',{'class':'views-field views-field-field-article-primary-category'}).text
        link= apis.find('a',{'class':'views-field views-field-pw-version-title'}).get('href')
        
        print('Name:',name,'\nDescription:', des ,'\ncategory', category ,'\nLink', link)
    url_tag=soup.find('a',{'title':'Go to next page'})
    if url_tag.get('href'):
        url= url_tag.get('href')
        print(url)
    else:
        break

AttributeError Traceback (most recent call last)
<ipython-input-26-1d8b226e6115> in <module>
7
8 for api in apis:
----> 9 name= apis.find('td',{"class":"views-field views-field-pw-version-title"}).text
10 des=apis.find('td',{'class':'views-field views-field-search-api-excerpt views-field-field-api-description hidden-xs visible-md visible-sm col-md-8'}).text
11 category=apis.find('td',{'class':'views-field views-field-field-article-primary-category'}).text

~\Anaconda3\lib\site-packages\bs4\element.py in __getattr__(self, key)
1576 def __getattr__(self, key):
1577 raise AttributeError(
-> 1578 "ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
1579 )

AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?