【发布时间】:2017-03-08 21:54:13
【问题描述】:
我正在尝试从以下网站的“a”类别下查找游戏列表。无论我尝试什么模式,我都可以直接在其中找到 id 属性值为“letter-a”的div,但找不到li 元素。
import bs4
import logging
import requests
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - \
%(levelname)s - %(message)s")
##res = requests.get("http://www.xbox.com/en-GB/xbox-one/backward-\
##compatibility")
res = requests.get("http://www.xbox.com/en-US/xbox-one/backward-\
compatibility/available-games")
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, "html.parser")
#game_elems = soup.select("body[id=\"DocumentBody\"] div[id=\"bodycolumn\"]")
game_elems = soup.select("#letter-a li")
logging.info("Length added elements: {}".format(len(game_elems)))
if game_elems:
logging.info("First element in 'game_elems': {}".format(str(game_elems[0])))
【问题讨论】:
-
你尝试过哪些模式?您尝试定位的 html 是什么样的?
-
Lots :) 添加了 html 的 img。
-
你忘了详细描述什么不起作用,你得到了什么输出,你想要什么输出。
标签: python web web-scraping beautifulsoup