解析使用BeautifulSoup不断更新的文本?

2024-06-09 13:59:15 发布

您现在位置:Python中文网/ 问答频道 /正文

在:http://arithmetic.zetamac.com/game?key=96823302上,我们需要将问题从<span>类中的problem标记中去掉。你知道吗

它是不断更新的,如何使用BeautifulSoup/Python每次检索数据?你知道吗

我知道会是这样的:

from bs4 import BeautifulSoup
soup = BeautifulSoup(requests.get("http://arithmetic.zetamac.com/game?key=96823302").content)
problem = soup.find("span",class_="problem") #Initial finding

a = True
while(a == True):
  print problem
  problem = soup.find("span",class_="problem")

//然后它将重新循环

但它只打印出来:<span class="problem"></span>而不是像2 + 22 x 2那样的内部


Tags: 数据key标记comgametruehttparithmetic