我正在使用BeautifulSoup尝试从网页中提取数据。但是由于某种原因,它无法对季节大于1的项目进行迭代。由于节点在我看来完全相同,因此似乎没有这种行为的原因。
def scrape_show(show): source = requests.get(show.url).text soup = BeautifulSoup(source, 'lxml') # All seasons and episodes area = soup.find('div', class_='play_video-area-aside play_video-area-aside--related-videos play_video-area-aside--related-videos--titlepage') for article in area: if "season" in article.get('id'): season = article.h2.a.find('span', class_='play_accordion__section-title-inner').text print(season + " -- " + article.get('id')) # All content for the given season ul = article.find('ul') if ul is None: print("null!") # This should not happen
示例输出:
Season 1 -- section-season1-xxxx
Season 2 -- section-season2-xxxx
null!
我正在使用BeautifulSoup尝试从网页中提取数据。但是由于某种原因,它无法对季节大于1的项目进行迭代。似乎没有理由因为...
数据并非在所有季节都可用HTML格式提供,仅在季节1可用。但是信息以JSON格式嵌入在页面中。您可以使用re
和json
模块解析此数据: