Guest User

Untitled

a guest
Apr 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. @staticmethod
  2. def get_videos(topic):
  3. """
  4. Get all the videos in the photos section
  5. :param topic:
  6. :return:
  7. """
  8. if topic != 'videos':
  9. raise ValueError('Topic should be videos')
  10. topic_url = DailyNation.BASE_URL + DailyNation.get_topics_url()[topic.lower()]
  11. html = DailyNation.get_html(topic_url)
  12. if html:
  13. videos = {}
  14. videos_list_div = html.find('div', class_='cb-content videolist')
  15. videos_topics = videos_list_div.find_all('div', class_='vh-caption')
  16. videos_caption_headings = []
  17. for caption_div in videos_topics:
  18. videos_caption_headings.append(DailyNation.clean_string(caption_div.find('h3').text))
  19. video_rows_divs = videos_list_div.find_all('div', class_='row')
  20. videos_caption_headings_count = 0
  21. for videos_item_div in video_rows_divs:
  22. trs = videos_item_div.find('table').find_all('tr')
  23. items = []
  24. for tr in trs:
  25. tds = tr.find_all('td')
  26. for td in tds:
  27. items.append({
  28. 'caption': td.find('div', class_='v-desc').text,
  29. 'image_url': td.find('div', class_='v-img').find('img').get('src'),
  30. 'story_url': DailyNation.BASE_URL + td.find(
  31. 'div',
  32. class_='col-lg-3 col-xs-12 col-sm-6 videoitem'
  33. ).find('a').get('href')
  34. })
  35. videos[videos_caption_headings[videos_caption_headings_count]] = items
  36. videos_caption_headings_count += 1
  37. return videos
Add Comment
Please, Sign In to add comment