我正在尝试提取字典条目:
url = 'http://www.lingvo.ua/uk/Interpret/uk-ru/вікно'
# parsed_url = urlparse(url)
# parameters = parse_qs(parsed_url.query)
# url = parsed_url._replace(query=urlencode(parameters, doseq=True)).geturl()
page = urllib.request.urlopen(url)
pageWritten = page.read()
pageReady = pageWritten.decode('utf-8')
xmldata = lxml.html.document_fromstring(pageReady)
text = xmldata.xpath(//div[@class="js-article-html g-card"])
无论是打开还是关闭注释行,它都会不断收到错误:
^{pr2}$
您的问题是URL路径中有非ASCII字符,必须使用python3中的urllib.parse.quote(string)或python2中的urllib.quote(string)正确编码。在
注意:根据What is the proper way to URL encode Unicode characters?,url应该被编码为UTF-8。但是,这并不排除对生成的非ASCII、UTF-8字符进行百分比编码。在
相关问题 更多 >
编程相关推荐