Python(2.7) splinter find element on a gb2312 webpage

45 Views Asked by At

I am trying to use splinter in python to interact with a web (http://bbs.nju.edu.cn/) which is encoded in gb2312. But I am facing problems finding elements. I am using notepad++ in UTF-8 w/o BOM edcoding. I have done a lot research and practiced to encode/decode as shown below. However, still not working. When it runs, it keeps outputting "No"

#coding=utf-8
import sys 
reload(sys) 
sys.setdefaultencoding('utf-8')

from splinter.browser import Browser

url = "http://bbs.nju.edu.cn/"
browser = Browser(driver_name = "chrome")
browser.visit(url)

str = u"新手求助"

if browser.is_text_present(str.decode("utf-8").encode("gb2312")):
    print "Yes"
else:
    print "No"
0

There are 0 best solutions below