나는 https://coinmarketcap.com/currencies/bitcoin/ 에서 구문 분석을 연습하고 있으며,이 정확한 <p>
태그 내에서 텍스트를 추출 할 수있는 방법을 알고 싶습니다. . 도와 주셔서 감사합니다.
import requests as r
from bs4 import BeautifulSoup
def find_info(self):
api = r.get(self.url) #url is above in the description
soup = BeautifulSoup(api.text, "html.parser")
soup.find_all('p')
# and here I'm stuck.
# I need to get the text from the chunk of HTML below.
<p>
<strong>
Bitcoin price today
</strong>
is ₽3.795.164 RUB with a 24-hour trading volume of ₽6.527.780.409.893 RUB. Bitcoin is down,12% in the last 24 hours. The current CoinMarketCap ranking is #1, with a market cap of ₽70.707.857.530.563 RUB. It has a circulating supply of 18.631.043 BTC coins and a max. supply of 21.000.000 BTC coins.
</p>
나는 다른 방법으로 그것을 시도했지만 많은 p 태그 중 정확한 것을 얻는 방법을 모릅니다.
a css selector
를 사용하여 원하는 단락을 잡습니다.
방법은 다음과 같습니다.
import requests
from bs4 import BeautifulSoup
page = requests.get("https://coinmarketcap.com/currencies/bitcoin/").content
print(BeautifulSoup(page, "html.parser").select_one('.about___1OuKY p').getText())
산출:
Bitcoin price today is $51,393.64 USD with a 24-hour trading volume of $88,784,693,272 USD. Bitcoin is up 4.87% in the last 24 hours. The current CoinMarketCap ranking is #1, with a market cap of $957,517,202,639 USD. It has a circulating supply of 18,631,043 BTC coins and a max. supply of 21,000,000 BTC coins.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다