This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
driver.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If page contains acccepted answer | |
if element_is_present('//div[@class="answer accepted-answer"]'): | |
answer = driver.find_element(By.XPATH, '//div[@class="answer accepted-answer"]//pre//code') | |
print("### Answer ###") | |
print(answer.text) | |
# If there is no accepted answer get all the code blocks from the topic | |
else: | |
code_blocks = wait.until(EC.presence_of_all_elements_located((By.XPATH, '//pre/code'))) | |
for i in range(0,len(code_blocks)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if page contains element | |
def element_is_present(xpath): | |
try: | |
driver.find_element(By.XPATH, xpath) | |
except NoSuchElementException: | |
return False | |
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results[0].click() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$x('//div[@class="r"]/a') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results = wait.until(EC.presence_of_all_elements_located((By.XPATH, '//div[@class="r"]/a'))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_input.send_keys(search_word + " site:stackoverflow.com") | |
search_input.send_keys(Keys.RETURN) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_input = driver.find_element_by_name("q") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while(True): | |
# Ask from user what to search | |
search_word = raw_input("What to search?: ") | |
# Uncomment this to run chrome normally | |
driver = webdriver.Chrome() | |
# If you want to run headless uncomment first three lines | |
#options = Options() | |
#options.set_headless(headless=True) | |
#driver = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import system | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.common.exceptions import NoSuchElementException |