You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB
Python

import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import requests
import os
import io
import multiprocessing
import json
DRIVER_PATH = '../geckodriver'
DRIVER_PATH2 = '../chromedriver'
def meta(queries,wd3):
url = 'https://www.google.it/search?q=vaast+colson&sxsrf=ALiCzsYcMyMvNo67pjpN-zRgfmTXw1L6Zw%3A1670252242664&source=hp&ei=0gaOY7zUJfbjxc8Pu_2QmAE&iflsig=AJiK0e8AAAAAY44U4oHBLhsJUz-SOp-oMy5eO2PMIDLU&gs_ssp=eJzj4tVP1zc0TDKvMDJMqjQzYPTiKUtMLC5RSM7PKc7PAwB8eAkY&oq=vaast+colsan&gs_lcp=Cgdnd3Mtd2l6EAEYADIHCC4QgAQQDTIGCAAQHhANMgYIABAeEA0yBggAEB4QDTIGCAAQHhANMggIABAIEB4QDToECCMQJzoLCC4QgAQQxwEQ0QM6CAguENQCEIAEOggILhCABBDUAjoFCAAQgAQ6BQguEIAEOgsILhCABBDHARCvAToOCC4QgAQQxwEQ0QMQ1AI6CAguEIAEEMsBOggIABCABBDLAToLCC4Q1AIQgAQQywE6DgguEK8BEMcBEIAEEMsBOgoIABCABBAKEMsBOgcIABCABBAKOgYIABAWEB46CAgAEBYQHhAKOgUIABCGA1AAWMkOYK0XaAFwAHgBgAHhAogB-RKSAQcxLjYuNS4xmAEAoAEB&sclient=gws-wiz'
wd3.get(url)
wd3.find_element(By.ID,'W0wltc').click()
dictionary = open('meta.json',)
l = json.load(dictionary)
print(l)
print('jsonjson!')
i=2
n = 0
while True:
try:
wd3.find_element(By.CSS_SELECTOR, "a[aria-label='Page {}']".format(i)).click()
searchResults = wd3.find_elements(By.CLASS_NAME, 'VwiC3b')
for result in searchResults:
#l = ''
l[n] = result.text
time.sleep(.5)
print(l)
n=n+1
with open("meta.json", "w") as outfile:
json.dump(l, outfile)
time.sleep(.5)
#wd2.execute_script(f"document.querySelector('#text').innerHTML += {result.text}")
print("Navigating to Next Page " + str(i))
i=i+1
time.sleep(1)
except:
print("Last page reached")
break
wd3 = webdriver.Chrome(executable_path=DRIVER_PATH2)
queries = ["VAAST COLSON"]
meta(queries,wd3)