我正在使用 Python 2。当我尝试将列表中的对象相乘时,它只会重复同一件事两次,即使我曾尝试使用它来解决问题:
map(float, prices)
我使用的代码是:
import urllib
from bs4 import BeautifulSoup
prices = []
htmlfile = urllib.urlopen("http://www.fifacoin.com/default/quick/listwithcategoryid? category_id=6").read()
soup = BeautifulSoup(htmlfile)
for item in soup.find_all('tr', {'data-price': True}):
prices.append(item['data-price'])
map(float, prices)
print prices[1] * 2
此代码仅输出价格 2 的值。我是 Python 新手,所以这可能是显而易见的事情
请您参考如下方法:
map 不改变原来的列表;它只是返回一个新列表。尝试:
prices = map(float, prices)
