Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Selenium webdriver和URIError:“0”;字符串包含非法的UTF-16序列;_Html_Selenium_Beautifulsoup_Python 3.5 - Fatal编程技术网

Html Selenium webdriver和URIError:“0”;字符串包含非法的UTF-16序列;

Html Selenium webdriver和URIError:“0”;字符串包含非法的UTF-16序列;,html,selenium,beautifulsoup,python-3.5,Html,Selenium,Beautifulsoup,Python 3.5,背景:我刚学了两天如何使用“Webdriver”和“Beautifulsoup” 问题: 我使用以下代码下载网页: 然后,我遇到了这个错误 WebDriverException: Message: URIError - String contained an illegal UTF-16 sequence. 尝试:我尝试用 (driver.page\u source)。编码('ascii','ignore') (driver.page\u source)。编码('utf-8') (建议人)

背景:我刚学了两天如何使用“Webdriver”和“Beautifulsoup”

问题: 我使用以下代码下载网页:

然后,我遇到了这个错误

WebDriverException: Message: URIError - String contained an illegal UTF-16 sequence.
尝试:我尝试用
(driver.page\u source)。编码('ascii','ignore')

(driver.page\u source)。编码('utf-8')
(建议人)
但还是以同样的错误结束

页面来源

我该怎么办?html中是否存在非法文本或其他内容?

谢谢你,我刚刚克服了这种情况。这是由不同的非UTF字符引起的

我用Edge驱动程序意外地解决了这个问题(Chrome和Mozilla无法处理这个问题)。因此,您可以使用它:

from selenium import webdriver
from bs4 import BeautifulSoup

driver = webdriver.Edge()
driver.get('https://mojim.com/twy100468x17x18.htm')
pageSource = driver.page_source
问题是Edge不像PhantomJS那样是无头的,所以当我刮的时候,我只在这个坏的例外链接上使用它。而且Egde几乎和PhantomJS一样快

from selenium import webdriver
from bs4 import BeautifulSoup

driver = webdriver.Edge()
driver.get('https://mojim.com/twy100468x17x18.htm')
pageSource = driver.page_source