metalx1000

Python and Selenium with Chrome

Apr 22nd, 2020 (edited)
1,265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. #!/usr/bin/python3
  2. #sudo apt install python-selenium unzip xvfb libxi6 libgconf-2-4 default-jdk
  3.  
  4. from selenium import webdriver
  5.  
  6. #Start Headless
  7. from selenium.webdriver.chrome.options import Options  
  8. options = Options()  
  9. options.headless = True
  10. driver = webdriver.Chrome(options=options)
  11. #End Headless
  12.  
  13. driver = webdriver.Chrome()
  14. driver.get('https://filmsbykris.com')
  15. source=driver.page_source
  16. print(source)
  17. search_box = driver.find_element_by_id("search")
  18. search_box.send_keys("Linux")
  19.  
  20. #First Video Link
  21. item = driver.find_element_by_class_name("portfolio-item")
  22. item.click()
  23.  
  24. #Array of elements
  25. videos = driver.find_elements_by_class_name("portfolio-item")
  26. video[4].click()
  27. search_box.clear()
  28.  
  29. #list all buttons
  30. buttons = driver.find_elements_by_class_name("btn")
  31. for b in buttons:
  32.   b.get_attribute('innerHTML')
  33.  
  34. #Using CSS selectors
  35. menu_item = driver.find_elements_by_css_selector(".page-scroll")
  36. for i in menu_item:
  37.   i.get_attribute('innerHTML')
  38.  
  39. #Get link by Link Text
  40. links = driver.find_elements_by_partial_link_text("LBRY")
  41. links[0].get_attribute('innerHTML')
  42. links[0].get_attribute('src')
  43. links[0].get_attribute('href')
  44.  
  45. #get Text of elements
  46. a=driver.find_elements_by_tag_name("a")
  47. for t in a:
  48.   t.text
Add Comment
Please, Sign In to add comment