-
Notifications
You must be signed in to change notification settings - Fork 0
/
myGenderChecker.py
executable file
·50 lines (44 loc) · 1.35 KB
/
myGenderChecker.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# Selenium stuff
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ElementNotVisibleException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
import os
import pickle
import StringIO
import re
import urllib2
import sys
from bs4 import BeautifulSoup
def findGender(source_code,NAME):
source = source_code.encode("utf-8")
for line in StringIO.StringIO(source):
if NAME in line and "ctl00_ContentPlaceHolder1_LabelSearchedFor" in line:
gender1 = line.split("ctl00_ContentPlaceHolder1_LabelSearchedFor").pop()
if "female" in gender1:
return "female"
#.split('bold;">').pop().split('<')[0]
elif "unisex" in gender1:
return "unisex"
elif "male" in gender1:
return "male"
else:
return "none"
for i in range(1):
browser = webdriver.Firefox()
browser.maximize_window()
browser.get("http://genderchecker.com/search.aspx")
time.sleep(3)
name = browser.find_element_by_name("ctl00$TextBoxName")
NAME = sys.argv[1]
name.send_keys(NAME,Keys.RETURN)
time.sleep(3)
source_code = browser.page_source
gender = findGender(source_code,NAME)
if gender is None:
gender = "None"
print(NAME+":"+gender+"\n")
browser.close()