小编uzd*_*ral的帖子

ValueError:int() 的无效文字,基数为 10:'196.41'

我不明白为什么它适用于不同的场景,但不适用于这个场景。基本上,一些绅士在这里帮助我改进了我的代码以刮取天气,这非常有效。然后我尝试做同样的事情来刮取 span 标签中的 ETH 值<span class="text-large2" data-currency-value="">$196.01</span>。所以,我在代码中采用了相同的技术,替换了字段,并希望它能够工作。

代码在这里:

import requests
from BeautifulSoup import BeautifulSoup
import time

url = 'https://coinmarketcap.com/currencies/litecoin/'

def ltc():
    while (True):
        response = requests.get(url)
        soup = BeautifulSoup(response.content)
        price_now = int(soup.find("div", {"class": "col-xs-6 col-sm-8 col-md-4 text-left"}).find(
        "span", {"class": "text-large2"}).getText())
        print(u"LTC price is: {}{}".format(price_now))
        # if less than 150
        if 150 > price_now:
            print('Price is Low')
        # if more than 200
        elif 200 < price_now:
            print('Price is high')

if __name__ == "__main__":
    ltc()
Run Code Online (Sandbox Code Playgroud)

输出如下所示:

Traceback (most …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping data-science valueerror

6
推荐指数
1
解决办法
4万
查看次数