Advertisement
iama_alpaca

DuckDuckGogler.py

Jul 10th, 2017
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #! /usr/bin/python3
  2. import requests, bs4, sys, urllib.parse
  3.  
  4. search = urllib.parse.quote(' '.join(sys.argv[1:])).replace('%20','+')
  5. res = requests.get('https://duckduckgo.com/html?q='+search, {'User-Agent': 'DuckDuckGogler'})
  6. soup = bs4.BeautifulSoup(res.text, 'html.parser')
  7. if "If this error persists, please let us know: ops@duckduckgo.com" in soup:
  8.     print("Sorry, sometimes duckduckgo doesn't want to work properly. Try running the script again.")
  9.     sys.exit()
  10.  
  11. results = soup.select('.web-result')
  12. rnum = 0
  13. for i in results:
  14.     rnum += 1
  15.     info = []
  16.     for item in i.text.splitlines():
  17.         if item.startswith("                  "):
  18.             item = item.replace("                  ","")
  19.         if not item == '' and not item == ' ':
  20.             info.append(item)
  21.     link = i.a['href'].replace("/l/?kh=-1&uddg=","")
  22.     print('\033[96m'+str(rnum)+': \033[92m'+info[0]+'\033[0m')
  23.     print('\033[93m'+urllib.parse.unquote(link)+'\033[0m')
  24.     print(info[1]+'\n\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement