wiby.py 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. import requests
  3. import re
  4. import tempfile
  5. import os
  6. import sys
  7. image_viewer = "palemoon"
  8. headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121201 icecat/17.0.1'}
  9. query = ""
  10. try:
  11. query = sys.argv[1]
  12. except:
  13. while not query:
  14. query = input("Searching for: ")
  15. search = f"https://wiby.me/?q={query}"
  16. search_result = requests.get(search, headers=headers)
  17. search_data = str(search_result.content)
  18. links = re.findall('<a class="tlink" href=.+?>.+?</a>',search_data)
  19. if "submitting a page." in search_data:
  20. print("Nothing found :(")
  21. quit()
  22. for i, link in enumerate(links):
  23. url = re.findall(r'(https?://\S+)', link)
  24. url = url[0].split('"')[0]
  25. title = re.sub("<a class=\"tlink\" href=\".+?\">","",link)
  26. title = title.replace("</a>","").replace("&#39;","'").replace("&amp;","&")
  27. print(i, title+"\n"+url)
  28. if i == 10:
  29. break