我正在尝试从此链接链接示例中提取排名文本编号:kaggle userranking no1。图像更清晰:
我正在使用以下代码:
def get_single_item_data(item_url):
sourceCode = requests.get(item_url)
plainText = sourceCode.text
soup = BeautifulSoup(plainText)
for item_name in soup.findAll('h4',{'data-bind':"text: rankingText"}):
print(item_name.string)
item_url = 'https://www.kaggle.com/titericz'
get_single_item_data(item_url)
结果是None
。问题是soup.findAll('h4',{'data-bind':"text: rankingText"})
输出:
[<h4 data-bind="text: rankingText"></h4>]
但是在检查时在链接的 html 中是这样的:
<h4 data-bind="text: rankingText">1st</h4>
. 可以在图片中看到:
很明显,缺少文本。我怎样才能超越它?
所以应该有办法通过soup
.
编辑 2:我尝试使用此stackoverflow question中投票最多的答案,但未成功。可能是那里的解决方案。