Chuk norris joke problem

url=“http://api.icndb.com/jokes
url_data=urlopen(url)
url_html=url_data.read()
url_data.close()
url_soup=soup(url_html,‘html.parser’)
print(url_soup)

and this
table=url_soup.findAll(‘pre’,attrs={‘style’:'word-wrap: break-word; white-space: pre-wrap;
'})
print(table)
why this statement is givuing error
pleasee reply

Hey @dipansha.chhabra19,

I would recommend you not to use beautiful soup here.
Since the API here is returning json format, therefore we just need to send a get request using this command requests.get(url) to the url, and the response it will return in json and therefore we can extract the joke easily.

Follow these simple steps:

  • Read the ID.csv and consider the values of IDs.
  • iterate over all the ids, and make a get request to the updated url (change id everytime)
  • from the response you get, extract the joke with json format, and append this joke to one list that was earlier initialized as empty.
  • make a dataframe with 2 columns ID and Joke, and convert it to csv format.

Thanks :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.