daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Jan 20th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. # Autor: Diego Lopez
  3.  
  4. from selenium import webdriver
  5. from selenium.webdriver.common.keys import Keys
  6. import time
  7. from selenium.common.exceptions import TimeoutException
  8. from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  9. import SocketServer
  10. import json
  11. from selenium.webdriver.common.by import By
  12.  
  13. from selenium.webdriver.support.ui import WebDriverWait
  14. from selenium.webdriver.support import expected_conditions as EC
  15. import signal
  16. from SocketServer import ThreadingMixIn
  17. import threading
  18.  
  19. class S(BaseHTTPRequestHandler):
  20.     def _set_headers(self):
  21.         self.send_response(200)
  22.         self.send_header('Content-type', 'text/html')
  23.         self.end_headers()
  24.  
  25.     def do_GET(self):
  26.        self._set_headers()
  27.        self.wfile.write("<html><body><h1>hi!</h1></body></html>")
  28.  
  29.     def do_HEAD(self):
  30.        self._set_headers()
  31.  
  32.    def do_POST(self):
  33.        # Doesn't do anything with posted data
  34.        content_length = int(self.headers['Content-Length']) # <--- Gets the
  35.        size of data
  36.        post_data = self.rfile.read(content_length) # <--- Gets the data itself
  37.        self._set_headers()
  38.        try:
  39.            data_string = json.loads(post_data)
  40.        except:
  41.            self.wfile.write('{"error" : "JSON"}')
  42.            return
  43.  
  44.        placa = str(data_string["placa"])
  45.        placa = placa.encode("utf8")
  46.        print post_data
  47.  
  48.        scraping(placa,self)
  49.  
  50.  
  51. class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
  52.     """Handle requests in a separate thread."""      
  53.  
  54.  
  55. def scraping(placa,self):
  56.     #Aqui realizo una operacion de scraping que me limito en mostrar.
  57.     self.wfile.write('{"estado" : "activo"}')
  58.     return
  59.  
  60.  
  61. if __name__ == "__main__":
  62.     server = ThreadedHTTPServer(('', 8888), S)
  63.     print 'Starting server, use <Ctrl-C> to stop'
  64.     server.serve_forever()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top