Python表的Scrape不返回d

2024-04-18 21:13:42 发布

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

我正在尝试使用Beautiful Soup对这个网站进行一些web抓取https://www.playtogga.com/leagues/5969cefb9dbb4f0001b3b539/players,并访问表中的数据。我目前的代码是:

https://www.playtogga.com/leagues/5969cefb9dbb4f0001b3b539/import requests
from bs4 import BeautifulSoup

import pandas as pd

headers = {'User-Agent': 
       'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like 
        Gecko) Chrome/47.0.2526.106 Safari/537.36'}

page = "https://www.playtogga.com/leagues/5969cefb9dbb4f0001b3b539/players"
pageTree = requests.get(page, headers=headers)
pageSoup = BeautifulSoup(pageTree.content, 'html.parser')

Players = pageSoup.find_all("a", {"class": "player-list"})

#Let's look at the first name in the Players list.
Players[0].text

但这会产生以下错误:

IndexError                                Traceback (most recent call last)
<ipython-input-42-b6ae920c924b> in <module>()
      1 #Let's look at the first name in the Players list.
----> 2 Players[0].text

IndexError: list index out of range

我在另一个网站上使用过这段代码,效果很好,当我检查type(Players)时,它会给我bs4.element.ResultSet,所以看起来它正在做一些事情

我有什么遗漏或做错了吗?我对这个很陌生,所以我想我可能错过了一些非常明显的东西。谢谢


Tags: the代码inhttpsimportcom网站www