【发布时间】:2018-06-09 00:39:59
【问题描述】:
想知道从 howlongtobeat.com 抓取多个网址的最佳方法是什么
我正在尝试将电子表格放在一起并需要这些数据
我的想法是 python3、beautifulsoup 和 selenium,但我不确定最好的方法
我正在使用 Linux (ubuntu 18.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 1/2 小时”(理想情况下是 30.5,但我认为我可以使用 excel,除非在此阶段有办法做到这一点)
让我知道我会怎么做
我需要硒吗?
谢谢,
【问题讨论】:
-
由于你想要的页面信息没有被 javascript 加载,你不应该需要 selenium
标签: python selenium web-scraping beautifulsoup