Python表的Scrape不返回任何数据
我正在尝试使用Beautiful Soup对该网站进行一些web抓取,并访问表中的数据。我目前的代码是:Python表的Scrape不返回任何数据,python,html,web-scraping,Python,Html,Web Scraping,我正在尝试使用Beautiful Soup对该网站进行一些web抓取,并访问表中的数据。我目前的代码是: 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) Appl
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
索引器错误回溯(最近一次调用)
在()
1#让我们看看球员名单中的第一个名字。
---->2名玩家[0]。文本
索引器:列表索引超出范围
我在另一个网站上使用过这段代码,效果很好,当我检查type(Players)时,它会给我bs4.element.ResultSet,所以看起来它正在做一些事情
我有什么遗漏或做错了吗?我对这个很陌生,所以我想我可能错过了一些非常明显的东西。谢谢 当我访问该URL时,我会看到欢迎屏幕,没有表格。也许这就是问题所在。打印出结果HTML,看看你实际得到了什么。是的,将我重定向到主页啊,对了,非常感谢你的回复。要访问URL,您需要登录,我在尝试运行代码时就是这样。但是,如果我打印HTML,它会给我与主页关联的HTML。这是否意味着在需要登录时访问页面的HTML时出现问题?