Orophix Orophix - 10 hours ago 2
Python Question

BeautifulSoup does not return results

I'm trying to make a scrapper that will print out all the house events on this url:

https://iflyer.tv/en-jp/listing/events/on/2017-07-22/

But I get back no results with the above code, any idea why?

from bs4 import BeautifulSoup
import requests

headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get("http://iflyer.tv/en-jp/listing/events/on/2017-07-22/")
soup = BeautifulSoup(response.text, "html.parser")

results= soup.find_all('div', {"class": "genre_list"})

for result in results:
print(result.find('HOUSE').get_text())

Answer

You're not looking for the right elements. You'll need to start with looking for a div that has a class holdevents. You then look for the dl attribute containing House. If found, scrape title and dates and add to a list.

from bs4 import BeautifulSoup
import requests

headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get("http://iflyer.tv/en-jp/listing/events/on/2017-07-22/")
soup = BeautifulSoup(response.text, "html.parser")
events = soup.find_all('div', {"class": "holdevent"})

house_events = []
for event in events:
    genre_list = event.find('dl', {"class": "genre_list"})

    if genre_list.find(text='House'):
        title = event.find('h1', {'class' : 'title'}).a.text
        date = event.find('h1', {'class' : 'nicedate'}).text
        house_events.append((title, date))

print(house_events)

This will fetch you:

[('Tropical Disco fueled by Chandon Passion', 'SAT, 22 Jul 2017'), 
 ('West House Crossover Connection VOL.5 -Zakuro 1st Anniversary', 'SAT, 22 Jul 2017'), 
 ('SUBCULTURE', 'SAT, 22 Jul 2017')]