Created
December 2, 2020 12:30
-
-
Save Ja7ad/82255a97692856e580e8ce7254bb2d23 to your computer and use it in GitHub Desktop.
Search Selected word in google and enter in speceficed site
This file contains 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 selenium import webdriver | |
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.webdriver.chrome.options import Options | |
import time , json | |
try: | |
options = webdriver.ChromeOptions() | |
options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"]) | |
#options.add_argument('headless') | |
#options.add_argument('window-size=1280x768') | |
options.add_argument("disable-gpu") | |
options.add_argument('no-sandbox') | |
options.add_argument('log-level=3') | |
options.add_argument('disable-infobars') | |
options.add_experimental_option("useAutomationExtension", False) | |
options.add_experimental_option("excludeSwitches",["enable-automation"]) | |
driver = webdriver.Chrome('./drv.exe', options=options) | |
driver.get('https://google.com') | |
search_query = 'نرم افزار حسابداری' | |
for i in range(60): | |
driver.get("https://www.google.com/search?q=" + search_query + "&start=" + str(10 * i)) | |
matched_elements = driver.find_elements_by_xpath('//a[starts-with(@href, "https://moeinsoft.com")]') | |
if matched_elements: | |
matched_elements[0].click() | |
break | |
y = 5 | |
for timer in range(0,50): | |
driver.execute_script("window.scrollTo(0, "+str(y)+")") | |
y += 500 | |
time.sleep(1) | |
time.sleep(20) | |
driver.quit() | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment