-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamfosscsv.py
30 lines (28 loc) · 915 Bytes
/
amfosscsv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from re import search
import csv
import time
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
import json
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
outputfile = open('xyz.csv', 'w')
csvwriter = csv.writer(outputfile)
with open('amfoss.json') as f :
data = json.loads(f.read())
for i in range(len(data)):
link = []
time.sleep(2)
query = data[i]["School_Name_EN"]
url = f"https://www.google.com/search?q={query}"
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'html.parser')
search = soup.find('div', class_="yuRUbf")
z = search.a.get('href')
z = str(z)
link.append(z)
print(query)
csvwriter.writerow(link)