mercredi 26 octobre 2016

BeautifulSoup: finding elements within elements

I'm attempting to find a list of games from the below website under the "a" category. I can find the div but not the li elements directly within no matter what pattern I try.

import bs4
import logging
import requests

logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - \
%(levelname)s - %(message)s")

##res = requests.get("http://ift.tt/2eG1YSO\
##compatibility")
res = requests.get("http://ift.tt/2eFjFEK\
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])))




Aucun commentaire:

Enregistrer un commentaire