1

I am new to Python. When I run the below code in Python for web scraping, I get an empty value. I am trying to print the Bitcoin price from the specified url. please help.

`import bs4`
 import requests
 url='https://coinmarketcap.com/'
 res=requests.get(url)
 soup = bs4.BeautifulSoup(res.text,'html.parser')

 element=soup.select('html.js.video.videoautoplay body div.container div.row div.col-lg-10 div.row div.col-xs-12 div.table-fixed-column-mobile.compact-name-column div#currencies_wrapper.dataTables_wrapper.no-footer table#currencies.table.dataTable.no-footer tbody tr#id-bitcoin.odd td.no-wrap.text-right a.price')
    print(element)
0

1 Answer 1

1

You don't have to follow the entire html structure, just select the item that holds the data you want.

import bs4
import requests

url = 'https://coinmarketcap.com/'
res = requests.get(url)
soup = bs4.BeautifulSoup(res.text,'html.parser')
element = soup.select_one('tr#id-bitcoin a.price').text

print(element)

$14122.10

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.