马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
未登录鱼C论坛账号在交流区发帖会弹出登录验证页面我用下面的代码模拟登录出错,求改正from urllib.request import HTTPPasswordMgrWithDefaultRealm,HTTPBasicAuthHandler,build_opener
from urllib.error import URLError
username='xxxxxxx'
passward='xxxxxxxxx'
url='https://fishc.com.cn/forum.php?mod=post&action=newthread&fid=173'
p=HTTPPasswordMgrWithDefaultRealm()
p.add_password(None,url,username,passward)
auth_handler=HTTPBasicAuthHandler(p)
opener=build_opener(auth_handler)
try:
result=opener.open(url)
html=result.read().decode('utf-8')
print(html)
except URLError as e:
print(e.reason)
File "C:/Users/tiger/PycharmProjects/spider/test2.py", line 20, in <module>
html=result.read().decode('utf-16')
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 2254-2255: illegal UTF-16 surrogate
Process finished with exit code 1
html = result.read().decode('gbk')
|