Created
January 10, 2018 16:00
-
-
Save serenamm/0eab75ce0fea74c9230105cdc19b530e 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
''' | |
Baidu for English to Canto characters | |
Chineseconverter.com for Canto characters to Jyutping | |
''' | |
def to_jyutping(sentence): | |
browser = initialize_browser() | |
browser.get("http://fanyi.baidu.com/#en/yue") | |
input_english = browser.find_element_by_id("baidu_translate_input") | |
input_english.send_keys(sentence) | |
sleep(3)# If I don't do sleep then it sometimes doesn't find the element | |
# Unicode to deal with Chinese characters ? May not be needed? | |
chinese_characters = browser.find_element_by_xpath('//*[@id="main-outer"]/div/div/div/div[2]/div[1]/div[2]/div/div/div[1]/p[2]').text | |
browser.close | |
browser = initialize_browser() | |
browser.get("https://www.chineseconverter.com/cantonesetools/en/cantonese-to-jyutping") | |
#sleep(1) | |
input_characters = browser.find_element_by_id("text") | |
#sleep(2) | |
input_characters.send_keys(chinese_characters) # This gives the problem | |
#sleep(2) | |
convert_button = browser.find_element_by_xpath("/html/body/div[3]/div[1]/div[2]/div/div[2]/form/div[3]/div/button").click() | |
jyutping = browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div/div[2]/form/div[1]/div[2]/div/div/div/div').text | |
return jyutping, chinese_characters | |
def main(): | |
sentence = input('Enter your input: ') | |
jyutping, chinese_characters = to_jyutping(sentence) | |
#print("English: " + sentence) | |
print("Traditional characters: " + chinese_characters) | |
print("Cantonese Jyutping: " + jyutping) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment