-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_answer.py
35 lines (28 loc) · 1010 Bytes
/
get_answer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
from urllib.parse import urlparse
import sys
class Fetcher:
def __init__(self, url):
self.driver = webdriver.PhantomJS()
self.driver.wait = WebDriverWait(self.driver, 5)
self.url = url
def lookup(self):
self.driver.get(self.url)
try:
ip = self.driver.wait.until(EC.presence_of_element_located(
(By.CLASS_NAME, "gsfi")
))
except:
print("Failed Bro!")
soup = BeautifulSoup(self.driver.page_source, "html.parser")
answer = soup.find_all(class_="_sPg")
if not answer:
answer = soup.find_all(class_="_m3b")
self.driver.quit()
return answer[0].get_text()