Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. from urllib.parse import urljoin
  4. import urllib.request
  5. from selenium import webdriver
  6. from selenium.webdriver.chrome.options import Options
  7. from selenium.common import exceptions
  8. from selenium.webdriver.common.by import By
  9. from selenium.webdriver.support.ui import WebDriverWait
  10. from selenium.webdriver.support import expected_conditions as EC
  11. from selenium.common.exceptions import StaleElementReferenceException, ElementNotVisibleException
  12. import time
  13.  
  14. chrome_options = Options()
  15. chrome_options.add_argument("--no-sandbox")
  16. chrome_options.add_argument("--disable-setuid-sandbox")
  17.  
  18. driver = webdriver.Chrome('C:/Users/User/webdriver/chromedriver.exe')
  19. driver.get("https://paperpaper.ru/category/what/news/")
  20. # wait = WebDriverWait(driver, 15)
  21.  
  22.  
  23.  
  24.     # def parse_news(driver):
  25. links_list = driver.find_element_by_class_name('link-black')
  26. href = links_list.get_attribute('href')
  27. linkLen = len(href)
  28. for i in range(0, linkLen):
  29.     link = WebDriverWait(driver,30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'link-black')))
  30.     link[i].click()
  31.     title = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, 'text-title__title'))).text
  32.     article = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'html body div div div article div div div.r-text-content'))).text
  33.     print('"' + title + '": ' + article)
  34.     driver.execute_script("window.history.go(-1)")
  35.  
  36. button = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'button.button-outline.r-container__more-button')))
  37. button.click()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement