Sep-16-2017, 09:45 PM
hi,
i am learning beautifulsoup to scrape data but whenever i run my code it gives atribute error that did you use find_all() when wanted to use find()?
this is my code below:
i tried everywhere to understand how to use find and find_all without attribute error, can someone explain what is going on? how to correctly use find() and find_all()
i am learning beautifulsoup to scrape data but whenever i run my code it gives atribute error that did you use find_all() when wanted to use find()?
this is my code below:
from bs4 import BeautifulSoup from urllib.request import urlopen url = "https://services.sccgov.org/facilityinspection/Closure/Index?sortField=sortbyEDate" html = urlopen(url) soup = BeautifulSoup(html, "html.parser") tble = soup.find("table", {"class":"table text-left table-responsive"}) getname = tble.find_all("td") for i in getname: name = i.find_all("a") contents = i.get_text() print(name) print(contents)first i kept find_all("a") out of the loop , it gave above error, then secondly i put it in loop like for i in getname.find_all("a")..it gave same above error and when i put i into loop it prints the results , however results needed more work but it prints? how?
i tried everywhere to understand how to use find and find_all without attribute error, can someone explain what is going on? how to correctly use find() and find_all()