Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/core/search_url.py
810 views
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
import requests
5
import urllib
6
from bs4 import BeautifulSoup
7
8
import core.colors as colors
9
10
11
def url_search(q):
12
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
13
# MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36"
14
query = q
15
query = query.replace(' ', '+')
16
URL = f"https://google.com/search?q={query}"
17
headers = {"user-agent": USER_AGENT}
18
res = requests.get(URL, headers=headers)
19
20
if res.status_code == 200:
21
soup = BeautifulSoup(res.content, "html.parser")
22
links = []
23
titles = []
24
25
for g in soup.find_all('div', class_='r'):
26
anchors = g.find_all('a')
27
if anchors:
28
link = anchors[0]['href']
29
title = g.find('h3').text
30
links.append(link)
31
titles.append(title)
32
33
dorks = dict(zip(links, titles))
34
for key, value in dorks.items():
35
print(f'{colors.bcolors.LOGGING}[*]{colors.bcolors.ENDC} {key} - {colors.bcolors.HEADER}{value}{colors.bcolors.ENDC}')
36
37
if len(dorks) == 0:
38
print(f'{colors.bcolors.BOLD}Ooops...No results found{colors.bcolors.ENDC}')
39
40
41