为了账号安全,请及时绑定邮箱和手机立即绑定

初学者求教

C:\Python27\python.exe C:/Users/wenfu/PycharmProjects/lian/baike_spider/spider_main.py

craw 1 : http://baike.baidu.com/item/Python

craw failed

craw 2 : http://baike.baidu.com/item/史记·2016?fr=navbar

Traceback (most recent call last):

  File "C:/Users/wenfu/PycharmProjects/lian/baike_spider/spider_main.py", line 37, in <module>

    obj_spider.craw(root_url)

  File "C:/Users/wenfu/PycharmProjects/lian/baike_spider/spider_main.py", line 21, in craw

    html_cont = self.downloader.download(new_url)

  File "C:\Users\wenfu\PycharmProjects\lian\baike_spider\html_downloader.py", line 10, in download

    response = urllib2.urlopen(url)

  File "C:\Python27\lib\urllib2.py", line 127, in urlopen

    return _opener.open(url, data, timeout)

  File "C:\Python27\lib\urllib2.py", line 404, in open

    response = self._open(req, data)

  File "C:\Python27\lib\urllib2.py", line 422, in _open

    '_open', req)

  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain

    result = func(*args)

  File "C:\Python27\lib\urllib2.py", line 1214, in http_open

    return self.do_open(httplib.HTTPConnection, req)

  File "C:\Python27\lib\urllib2.py", line 1181, in do_open

    h.request(req.get_method(), req.get_selector(), req.data, headers)

  File "C:\Python27\lib\httplib.py", line 995, in request

    self._send_request(method, url, body, headers)

  File "C:\Python27\lib\httplib.py", line 1029, in _send_request

    self.endheaders(body)

  File "C:\Python27\lib\httplib.py", line 991, in endheaders

    self._send_output(message_body)

  File "C:\Python27\lib\httplib.py", line 844, in _send_output

    self.send(msg)

  File "C:\Python27\lib\httplib.py", line 820, in send

    self.sock.sendall(data)

  File "C:\Python27\lib\socket.py", line 224, in meth

    return getattr(self._sock,name)(*args)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-12: ordinal not in range(128)


Process finished with exit code 1

这是什么错误啊

正在回答

1 回答

至少代码是有问题的

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Python开发简单爬虫
  • 参与学习       227670    人
  • 解答问题       1219    个

本教程带您解开python爬虫这门神奇技术的面纱

进入课程

初学者求教

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信