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
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
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
$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[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
# 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
# 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
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
system('cls') |
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
system('clear') |