【发布时间】:2017-12-02 02:26:08
【问题描述】:
当我尝试执行代码时,输出值显示了两次。有没有办法只显示一次?
import requests
from bs4 import BeautifulSoup
def powr(url):
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'html.parser')
for text in soup.findAll('span', {'class': 'coin-page__price-number'}):
head = text.string
#print('Vertcoin =', head)
print(head)
powr('https://coinranking.com/coin/power-ledger-powr')
输出:
0.695
0.695
【问题讨论】:
-
尝试使用 find 而不是 find_all
-
非常感谢。它工作:)
-
好的,那么我将添加一个答案以供将来参考。 :-)
-
当然。那太好了!
-
把
break放在print语句后面就可以解决问题了。
标签: python beautifulsoup request