BeautifulSoup不会返回结果

时间:2017-07-17 11:04:44

标签: python python-3.x web-scraping beautifulsoup bs4

我试图制作一个会在这个网址上打印出所有家庭活动的剪贴板:

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

但是我用上面的代码得不到任何结果,任何想法为什么?

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())

3 个答案:

答案 0 :(得分:1)

您并未寻找合适的元素。您需要首先查找具有类div的{​​{1}}。然后,您会查找包含holdevents的{​​{1}}属性。如果找到,请删除标题和日期并添加到列表中。

dl

这会抓住你:

House

答案 1 :(得分:0)

您应该再次检查HTML代码。 class =“genre_list”

没有div标签

阅读本文以获取有关如何使用bs4进行刮擦的更多信息: http://web.stanford.edu/~zlotnick/TextAsData/Web_Scraping_with_Beautiful_Soup.html

答案 2 :(得分:0)

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": "holdevent"})
for result in results:
    print('event')
    print(result.find('h1', {"class": "nicedate"}).get_text())
    print(result.find('h1', {"class": "title"}).get_text())
相关问题