File tree 1 file changed +19
-10
lines changed
1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change 1
1
import webbrowser
2
2
from sys import argv
3
- from urllib .parse import quote
3
+ from urllib .parse import quote , parse_qs
4
+ from fake_useragent import UserAgent
4
5
5
6
import requests
6
7
from bs4 import BeautifulSoup
13
14
14
15
print ("Googling....." )
15
16
16
- url = f"https://www.google.com/search?q={ query } &num=2 "
17
+ url = f"https://www.google.com/search?q={ query } &num=100 "
17
18
18
19
res = requests .get (
19
20
url ,
20
21
headers = {
21
- "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) "
22
- "Gecko/20100101 Firefox/98.0"
22
+ "User-Agent" : str (UserAgent ().random )
23
23
},
24
24
)
25
25
26
- link = (
27
- BeautifulSoup (res .text , "html.parser" )
28
- .find ("div" , attrs = {"class" : "yuRUbf" })
29
- .find ("a" )
30
- .get ("href" )
31
- )
26
+ try :
27
+ link = (
28
+ BeautifulSoup (res .text , "html.parser" )
29
+ .find ("div" , attrs = {"class" : "yuRUbf" })
30
+ .find ("a" )
31
+ .get ("href" )
32
+ )
33
+
34
+ except AttributeError :
35
+ link = parse_qs (
36
+ BeautifulSoup (res .text , "html.parser" )
37
+ .find ("div" , attrs = {"class" : "kCrYT" })
38
+ .find ("a" )
39
+ .get ("href" )
40
+ )["url" ][0 ]
32
41
33
42
webbrowser .open (link )
You can’t perform that action at this time.
0 commit comments