|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这一讲的内容是爬取有道词典的翻译
不知道是不是有道现在的反扒机制问题
我照着小甲鱼讲的内容写了如下代码import urllib.request
import urllib.parse
url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
data = {}
data['i']= 'I love you'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '15859027263185'
data['sign'] = '5cca501aea3f69e106e23fe480441491'
data['ts'] = '1585902726318'
data['bv'] = '43e486d853ef63af6932375b449635ab'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_CLICKBUTTION'
response = urllib.request.urlopen(url, data)
html = response.read.decode('utf-8')
print(html)
然后报错:
File "<ipython-input-1-eb45bad087c0>", line 1, in <module>
runfile('C:/Users/FLX/Documents/py source code new/test.py', wdir='C:/Users/FLX/Documents/py source code new')
File "C:\Users\FLX\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "C:\Users\FLX\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/FLX/Documents/py source code new/test.py", line 21, in <module>
response = urllib.request.urlopen(url, data)
File "C:\Users\FLX\Anaconda3\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\FLX\Anaconda3\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\FLX\Anaconda3\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\FLX\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\FLX\Anaconda3\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\FLX\Anaconda3\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\FLX\Anaconda3\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\FLX\Anaconda3\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\FLX\Anaconda3\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\FLX\Anaconda3\lib\http\client.py", line 1064, in _send_output
+ b'\r\n'
TypeError: can't concat str to bytes
编译器是spyder
有没有人知道这是怎么一回事啊?
1,Python没有编译器一说。
2,倒数第二行,read()的括号加上
|
|