数据刮取howlongtobeat.com网站用Python3,靓汤,硒(也许)

2024-09-28 05:22:32 发布

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

想知道最好的方法是从howlongtobeat.com网站会是

我想把一个电子表格放在一起,需要这些数据

我的想法是给我们Python3,美丽的苏泊尔,硒,但不知道最好的方式去做

我正在使用Linux(Ubuntu18.04)命令控制台,可以使用一些技巧(非常新)

这是我目前掌握的代码:

url = 'https://howlongtobeat.com/game.php?id=38050'

response = get(url)

from bs4 import BeautifulSoup

html_soup = BeautifulSoup(response.text, 'html.parser')
type(html_soup)

game_containers = html_soup.find_all('div', class_ = 'li.short:nth-of-type(2)')

first_game = game_containers[0]
first_game.text

出现如下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

之后返回:

'\nGod of War (2018) '

我想从中得到的是页面上的“30个半小时”(理想情况下是30.5小时,但我认为我可以使用excel,除非在这个阶段有办法做到这一点)

告诉我该怎么做

我需要硒吗?你知道吗

谢谢你


Tags: of方法textcomgameurl网站response
1条回答
网友
1楼 · 发布于 2024-09-28 05:22:32
game_containers = soup.find_all('div', class_='game_times')

返回game_times统计表的ResultSet。你知道吗

使用[-1]获取最后一项,并获取其text

print(game_containers[-1].find_all({'li': '    short time_100 shadow_box'})[-1].contents[3].get_text())

打印:
30½ Hours

相关问题 更多 >

    热门问题