我正在使用以下代码从.txt文件中读取一些非英文(Chienese)文本。如何编码用于硒中的非英文网页链接
f = open('C:\data\chinese.txt')
for line in f:
print line # this displays the chinese characters properly in console
currelem = d.find_element_by_xpath("//a[contains(.," + line + ")]") # this gives error as mentioned below/
错误消息:
InvalidSelectorException: Message: u'The given selector //a[contains(.,\ufeff\'\u8054\u7edc\u6211\u4eec\'\n)] is either invalid or does not result in a WebElement
有什么办法来解决这个问题?
你还没有说过你用来保存文件的工具。如果您正在使用程序,请显示您正在使用的方法。 – Vorsprung
我在这里使用.txt文件。在我的问题中也添加了详细信息。 谢谢。 – Shan
所以,'chinese.txt'实际上包含原始的html权限?看起来像是每行一页......(你可能已经做了一些预处理来删除每一行中的新行字符,对吗?) –