2021年3月24日星期三

remove html tags from string using bs4

I'm trying to make a program to read the price of bitcoin from a website. I used bs4 and was bale to get the section I was looking for but its surrounded by the html tags.

   output: <div class="priceValue___11gHJ">$52,693.18</div>    

I just want the price and i have tried the regex and lxml methods, but I keep getting errors

import requests  from bs4 import BeautifulSoup    #get url  url = "https://coinmarketcap.com/currencies/bitcoin/"  r = requests.get(url)    #parse html  soup = BeautifulSoup(r.content, 'html5lib')    #find div  find_div = soup.find('div', {"class": "priceValue___11gHJ"})  print(find_div)  
https://stackoverflow.com/questions/66792485/remove-html-tags-from-string-using-bs4 March 25, 2021 at 11:06AM

没有评论:

发表评论