想知道如何通过beautifulsoup提取游戏名称
我想我对它的HTML方面有问题
到目前为止,我得到的是:
from requests import get
url = 'https://howlongtobeat.com/game.php?id=38050'
response = get(url)
from bs4 import BeautifulSoup
html_soup = BeautifulSoup(response.text, 'html.parser')
game_length = html_soup.find_all('div', class_='game_times')
length = (game_length[-1].find_all({'li': ' short time_100 shadow_box'})[-1].contents[3].get_text())
print(length)
game_name = html_soup.find_all('div', class_='profile_header_game')
game = (game_name[].find({"profile_header shadow_text"})[].contents[].get_text())
print(game)
我知道长度但不知道游戏名为什么?你知道吗
对于打印(长度)打印:
31 Hours
但对于打印(游戏)打印:
game_name = html_soup.find_all('div', class_='profile_header_game')
game = (game_name[].find({"profile_header shadow_text"})[].contents[].get_text()) File "", line 1 game = (game_name[].find({"profile_header shadow_text"})[].contents[].get_text()) ^ SyntaxError: invalid syntax
print(game) Traceback (most recent call last): File "", line 1, in NameError: name 'game' is not defined
我做错什么了?你知道吗
较短版本
您的代码中似乎存在一些语法问题。以下是更正的版本:
相关问题 更多 >
编程相关推荐