-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.py
More file actions
43 lines (25 loc) · 837 Bytes
/
scrape.py
File metadata and controls
43 lines (25 loc) · 837 Bytes
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
29
30
31
32
33
34
35
36
37
import requests,webbrowser
from bs4 import BeautifulSoup
from textblob import TextBlob
from pprint import pprint
import re
import pandas
titles=[]
linksArray=[]
user_input=input("Enter to search:")
google_search= requests.get("https://www.google.com/search?q="+user_input)
soup=BeautifulSoup(google_search.text,'lxml')
# print(soup.prettify())
headline_results = soup.findAll("div", {"class": "BNeawe vvjwJb AP7Wnd"})
for fields in headline_results[:6]:
titles.append(fields.text)
# print((titles))
search_results=soup.select('.kCrYT a')
for link in search_results[:6]:
mainLink=link.get('href')
linksArray.append(mainLink)
# print(len(linksArray))
# FOR CSV
df = pandas.DataFrame(data={"Headline": titles, "Link": linksArray})
df.to_csv("./flightStatus.csv", sep=',',index=False)
print("CSV file created")