Created
March 10, 2020 17:23
-
-
Save enesusta/347cd30eedf06243d6e6be6a29ab3e62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socketserver | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
from urllib.parse import parse_qs | |
import requests | |
from bs4 import BeautifulSoup | |
import urllib3 | |
import codecs | |
import sys | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'} | |
class Serv(BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.end_headers() | |
self.wfile.write(bytes('test', 'utf-8')) | |
path = self.path | |
qs = {} | |
if '?' in path: | |
path, tmp = path.split('?',1) | |
qs = parse_qs(tmp) | |
page = requests.get("https://tureng.com/en/turkish-english/%s" %qs.get("word"), headers=headers, timeout=(20,20), verify=False) | |
soup = BeautifulSoup(page.text,'html.parser') | |
list = soup.find_all("td", class_="tr ts") | |
arr = self.toList(list) | |
self.wfile.write(bytes("".join(str(x) for x in arr), "utf-8")) | |
def toList(self,list): | |
arr = [] | |
for i in list: | |
arr.append(i.find(text=True)) | |
return arr | |
httpd = HTTPServer(('localhost', 8080), Serv) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment