找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 384|回复: 0

[求助] 调用自己定义的函数,报错

0

主题

0

帖子

0

积分

贫民

积分
0
SimaSmile 发表于 2019-5-10 15:05:57 | 显示全部楼层 |阅读模式
本帖最后由 SimaSmile 于 2019-5-10 15:09 编辑
  1. <pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:9.8pt;"><span style="color:#cc7832;">from </span>bs4 <span style="color:#cc7832;">import </span>BeautifulSoup
  2. <span style="color:#cc7832;">import </span>requests
  3. <span style="color:#cc7832;">import </span>pymongo

  4. mongo_db = pymongo.MongoClient(<span style="color:#6a8759;">'loacllhost'</span><span style="color:#cc7832;">,</span><span style="color:#6897bb;">27017</span>)
  5. ku = mongo_db[<span style="color:#6a8759;">'tongcheng'</span>]
  6. ku_biao = ku[<span style="color:#6a8759;">'cate_urls'</span>]

  7. cate_url = <span style="color:#6a8759;">'https://xa.58.com'
  8. </span>start_url = <span style="color:#6a8759;">'https://xa.58.com/sale.shtml'
  9. </span><span style="color:#6a8759;">
  10. </span><span style="color:#6a8759;">
  11. </span><span style="color:#cc7832;">def </span><span style="color:#ffc66d;">get_cate_urls</span>(url):
  12.     wb_data = requests.get(url)
  13.     soup = BeautifulSoup(wb_data.text<span style="color:#cc7832;">, </span><span style="color:#6a8759;">'lxml'</span>)
  14.     links = soup.select(<span style="color:#6a8759;">'ul.ym-submnu > li > b > a'</span>)
  15.     <span style="color:#cc7832;">for </span>link <span style="color:#cc7832;">in </span>links:
  16.         cate_name = link.get_text()
  17.         page_url = cate_url + link.get(<span style="color:#6a8759;">'href'</span>)
  18.         <span style="color:#cc7832;">if </span>cate_name == <span style="color:#6a8759;">'</span><span style="color:#cc7832;">\xa0</span><span style="color:#6a8759;">'</span>:
  19.             <span style="color:#cc7832;">pass
  20. </span><span style="color:#cc7832;">        else</span>:
  21.             data = {
  22.                 <span style="color:#6a8759;">'cate_name'</span>: cate_name<span style="color:#cc7832;">,
  23. </span><span style="color:#cc7832;">                 </span><span style="color:#6a8759;">'page_url'</span>: page_url
  24.             }
  25.         ku_biao.insert_one(data)


  26. get_cate_urls(start_url)</pre>
复制代码
报错信息如下

  1. Traceback (most recent call last):
  2.   File "F:/python/58/Cate_List.py", line 30, in <module>
  3.     get_cate_urls(start_url)
  4.   File "F:/python/58/Cate_List.py", line 27, in get_cate_urls
  5.     ku_biao.insert_one(data)
  6.   File "F:\python\58\venv\lib\site-packages\pymongo\collection.py", line 700, in insert_one
  7.     session=session),
  8.   File "F:\python\58\venv\lib\site-packages\pymongo\collection.py", line 614, in _insert
  9.     bypass_doc_val, session)
  10.   File "F:\python\58\venv\lib\site-packages\pymongo\collection.py", line 602, in _insert_one
  11.     acknowledged, _insert_command, session)
  12.   File "F:\python\58\venv\lib\site-packages\pymongo\mongo_client.py", line 1279, in _retryable_write
  13.     with self._tmp_session(session) as s:
  14.   File "D:\Python\lib\contextlib.py", line 112, in __enter__
  15.     return next(self.gen)
  16.   File "F:\python\58\venv\lib\site-packages\pymongo\mongo_client.py", line 1611, in _tmp_session
  17.     s = self._ensure_session(session)
  18.   File "F:\python\58\venv\lib\site-packages\pymongo\mongo_client.py", line 1598, in _ensure_session
  19.     return self.__start_session(True, causal_c**istency=False)
  20.   File "F:\python\58\venv\lib\site-packages\pymongo\mongo_client.py", line 1551, in __start_session
  21.     server_session = self._get_server_session()
  22.   File "F:\python\58\venv\lib\site-packages\pymongo\mongo_client.py", line 1584, in _get_server_session
  23.     return self._topology.get_server_session()
  24.   File "F:\python\58\venv\lib\site-packages\pymongo\topology.py", line 429, in get_server_session
  25.     None)
  26.   File "F:\python\58\venv\lib\site-packages\pymongo\topology.py", line 200, in _select_servers_loop
  27.     self._error_message(selector))
  28. pymongo.errors.ServerSelectionTimeoutError: loacllhost:27017: [Errno 11001] getaddrinfo failed
复制代码


2.png
微信截图_20190510150701.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表