我如何使用 beautifulsoup 提取值?

How do i extract values with beautifulsoup?

您好,我正在使用漂亮的汤来提取欧元对我们的价值,这是我目前得到的结果:

import requests
from bs4 import BeautifulSoup

def Euro_spider():
    url = 'http://fx-rate.net/USD/'
    source_code = requests.get(url)
    plain_text = source_code.text
    soup = BeautifulSoup(plain_text, "html.parser")

接下来我该做什么?

现在您需要找到包含汇率的正确元素:

<a href="/USD/EUR/" class="1rate" title="Dollar to Euro">0.895</a>

你可以找到它,例如title:

usd_to_euro = soup.find(title="Dollar to Euro").get_text()
print(usd_to_euro)  # prints 0.895