Advertisement
Guest User

Shitpost

a guest
Nov 24th, 2017
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import pandas as pd
  2. from bs4 import BeautifulSoup as bs
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. from selenium.webdriver.common.keys import Keys
  7. from selenium.webdriver.support import expected_conditions as EC
  8. from selenium.common.exceptions import TimeoutException, NoSuchElementException, UnexpectedAlertPresentException, WebDriverException
  9. from selenium.webdriver.chrome.options import Options
  10. import time
  11.  
  12. count_1 = 0
  13. count_2 = 0
  14.  
  15. opts = Options()
  16. opts.add_argument("my-user-agent")
  17.  
  18. driver = webdriver.Chrome('/Users/MyName/bin/chromedriver', chrome_options=opts)
  19.  
  20. driver.wait = WebDriverWait(driver, 15)
  21.  
  22. res = ''
  23.  
  24. page = driver.get('https://www.springfieldspringfield.co.uk/episode_scripts.php?tv-show=the-secret-life-of-the-american-teenager')
  25.  
  26. soup = bs(driver.page_source, 'html.parser')
  27.  
  28. episodes = soup.find_all('a', class_= 'season-episode-title')
  29.  
  30. per_ep = []
  31.  
  32. print (1198/len(episodes))
  33.  
  34. for i in episodes:
  35.     count = 0
  36.     driver.get('https://www.springfieldspringfield.co.uk/'+i['href'])
  37.     soup = bs(driver.page_source, 'html.parser')
  38.     container = soup.find('div',class_='scrolling-script-container')
  39.     for j in container.text.split(' '):
  40.         if j == 'sex':
  41.             count += 1
  42.             count_1 += 1
  43.         if j == 'the':
  44.             count_2 += 2
  45.     per_ep.append((count,episodes.index(i)))
  46.  
  47.  
  48.  
  49.  
  50.     print (count_1)
  51.     print (count_2)
  52.     driver.back()
  53.  
  54. print (count_1/count_2)
  55.  
  56. counts = []
  57. for i in per_ep:
  58.     counts.append(i[0])
  59.  
  60. for i in per_ep:
  61.     if i[0] == max(counts):
  62.         print (i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement