Skip to content
Advertisement

Retriving data from div and header classes using pyhton urllib.request and bs4

I am trying to create a python program which is capable of getting the objects title and its cost from ‘https://coinmarketcap.com/’ website. in this image i have my initial code. I keep getting an error that says:

JavaScript

however, both the ‘priceHeading’ & ‘priceValue’ class have values of ‘bitcoin price’ and ‘29,000’ respectively. How do I get those values?

here’s my initial code:

JavaScript

Advertisement

Answer

You probably received compressed response from the server which urllib.request cannot handle. Instead of urllib.request use requests module:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement