SHARE
TWEET

Python - pokedex.org

furas May 30th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import selenium.webdriver.common
  4. import bs4
  5. import time
  6.  
  7. option = selenium.webdriver.ChromeOptions()
  8. option.add_argument('headless')
  9. driver = selenium.webdriver.Chrome('C:/Users/Asus/Downloads/Compressed/chromedriver.exe', chrome_options=option)
  10. #driver = selenium.webdriver.Chrome('/home/furas/bin/chromedriver', chrome_options=option)
  11.  
  12. driver.get('https://www.pokedex.org/')
  13.  
  14. # --- scroll down ---
  15.  
  16. results = []
  17.  
  18. for x in range(30): # TODO: different method to get "end of page"
  19.     selenium.webdriver.ActionChains(driver).send_keys(selenium.webdriver.common.keys.Keys.PAGE_DOWN).perform()
  20.     time.sleep(0.3) # it needs time to load new data
  21.    
  22.     src = driver.page_source
  23.  
  24.     soup = bs4.BeautifulSoup(src, 'lxml')
  25.     ul = soup.find('ul', id='monsters-list').find_all('li')
  26.  
  27.     for li in ul:
  28.         name = li.find('span')
  29.         if name:
  30.             print(name.text)
  31.             if name not in results:
  32.                 results.append(name.text)
  33.  
  34. print('len:', len(results))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top