chenhuimingdeMacBook-Pro:groceryList Mch$

sudo pip3 install beautifulsoup4

The directory '/Users/Mch/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/Mch/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting beautifulsoup4
Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Could not find a version that satisfies the requirement beautifulsoup4 (from versions: )
No matching distribution found for beautifulsoup4

Solution:

* reinstall python?

brew reinstall python

  

==> Reinstalling python
==> Installing dependencies for python: gdbm
==> Installing python dependency: gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.17.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gdbm-1.17.el_capitan.bottle.tar.gz
/usr/local/Cellar/gdbm/1.17: 20 files, 586.2KB
==> Installing python
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.0.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring python-3.7.0.el_capitan.bottle.1.tar.gz
==> /usr/local/Cellar/python/3.7.0/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/p
==> /usr/local/Cellar/python/3.7.0/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/p
==> /usr/local/Cellar/python/3.7.0/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/p
==> Caveats
Python has been installed as
/usr/local/bin/python3 Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin If you need Homebrew's Python 2.7 run
brew install python@2 Pip, setuptools, and wheel have been installed. To update them run
pip3 install --upgrade pip setuptools wheel You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
/usr/local/Cellar/python/3.7.0: 4,787 files, 102MB
==> Caveats
==> python
Python has been installed as
/usr/local/bin/python3 Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin If you need Homebrew's Python 2.7 run
brew install python@2 Pip, setuptools, and wheel have been installed. To update them run
pip3 install --upgrade pip setuptools wheel You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages See: https://docs.brew.sh/Homebrew-and-Python

ouput

* install pip3

brew install pip3

  

Error: No available formula with the name "pip3"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Warning: Error searching on GitHub: GitHub
The GitHub credentials in the macOS keychain may be invalid.
Clear them with:
printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase
Or create a personal access token:
https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrew
and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"

Error: No formulae found in taps.

* Clear The GitHub credentials in the macOS keychain

printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase

  

* create a personal access token

https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrew

Generate token

.btn { position: relative; display: inline-block; padding: 6px 12px; font-size: 14px; font-weight: 600; line-height: 20px; white-space: nowrap; vertical-align: middle; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-repeat: repeat-x; background-position: -1px -1px; background-size: 110% 110%; border: 1px solid rgba(27, 31, 35, 0.2); border-radius: 0.25em; -webkit-appearance: none; -moz-appearance: none; appearance: none }
.btn-primary { color: rgba(255, 255, 255, 1); background-color: rgba(40, 167, 69, 1); background-image: linear-gradient(-180deg, rgba(52, 208, 88, 1) 0, rgba(40, 167, 69, 1) 90%) }

* Click Button "Generate token"

https://github.com/settings/tokens

把这个40位的token粘贴出来

* emacs ~/.bash_profile

echo 'export HOMEBREW_GITHUB_API_TOKEN="your_token"' >> ~/.bash_profile
. !$

  

* 再试安装beautifulsoup4

pip3 install beautifulsoup4

  

Collecting beautifulsoup4
Downloading https://files.pythonhosted.org/packages/fe/62/720094d06cb5a92cd4b3aa3a7c678c0bb157526a95c4025d15316d594c4b/beautifulsoup4-4.6.1-py3-none-any.whl (89kB)
100% |████████████████████████████████| 92kB 180kB/s
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.6.1

* upgrade pip

sudo curl https://bootstrap.pypa.io/get-pip.py | python3

  

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/pip'

Consider using the `--user` option or check the permissions.

sudo chown -hR `whoami`:staff /usr/local/bin/

output:  

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload Upload Total Spent Left Speed
100 1604k 100 1604k 0 0 443k 0 0:00:03 0:00:03 --:--:-- 445k
Collecting pip
Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 18.0
Uninstalling pip-18.0:
Successfully uninstalled pip-18.0
Successfully installed pip-18.0

  

* 在引用bs4 “frombs4 import BeautifulSoup”时还会报错“ModuleNotFoundError: Nomodule named 'bs4'.” 未找到名为bs4的模块,这时需要在Pycharm上安装bs4模块来解决

按Cmd(win) + , (windows图标键 和 逗号 一起按)或者点 Pycharm => Preferences

windows下 File => settings

* 点击 右边框 左下角 + install

bs  再点击 "Install Package"

这行代码不报错了

from bs4 import BeautifulSoup

  

* 创建python文件

#-*- coding: UTF-8 -*-
#!/usr/local/bin/python3 from urllib.request import urlopen
from bs4 import BeautifulSoup html = urlopen("http://pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read())
print(bsObj.h1)

  Run:

/Users/Mch/PycharmProjects/BeautifulSoup/venv/bin/python
/Users/Mch/PycharmProjects/BeautifulSoup/index.py
/Users/Mch/PycharmProjects/BeautifulSoup/index.py:8:
UserWarning: No parser was explicitly specified,
so I'm using the best available HTML parser for this system ("html.parser").
This usually isn't a problem, but if you run this code on another system,
or in a different virtual environment,
it may use a different parser and behave differently. The code that caused this warning is on line 8 of the file
/Users/Mch/PycharmProjects/BeautifulSoup/index.py.
To get rid of this warning,
pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor. bsObj = BeautifulSoup(html.read())
<h1>An Interesting Title</h1> Process finished with exit code 0

  

* 这里有一个警告️第8行出错

根据提示

To get rid of this warning,pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor.

找到这个构造函数在文件/Users/Mch/PycharmProjects/BeautifulSoup/venv/lib/python3.7/site-packages/bs4/__init__.py

    def __init__(self, markup="", features=None, builder=None,
parse_only=None, from_encoding=None, exclude_encodings=None,
**kwargs):

  

因此在第8行添加参数 'html.parser'

bsObj = BeautifulSoup(html.read(), 'html.parser')

 再运行:

/Users/Mch/PycharmProjects/BeautifulSoup/venv/bin/python /Users/Mch/PycharmProjects/BeautifulSoup/index.py
<h1>An Interesting Title</h1>

Process finished with exit code 0

warning没有了

* try ... except... else

#-*- coding: UTF-8 -*-
#!/usr/local/bin/python
from urllib.request import urlopen
from bs4 import BeautifulSoup from urllib.request import HTTPError
# import socket
# socket.setdefaulttimeout(3) try:
# html = urlopen("http://pythonscraping.com/pages/page1.html", None, 3)
# 设置超时时间为3s
html = urlopen("http://nosuchurl", None, 3)
except HTTPError as e:
print(e)
else:
bsObj = BeautifulSoup(html.read(), 'html.parser')
print(bsObj.body.div)

  

* 可靠的网络连接

#-*- coding: UTF-8 -*-
#!/usr/local/bin/python
from urllib.request import urlopen
from urllib.request import HTTPError, URLError
from bs4 import BeautifulSoup def getTitle(url):
try:
html = urlopen(url, None, 3)
except(HTTPError, URLError) as e:
return None
try:
bsObj = BeautifulSoup(html.read(), "html.parser")
title = bsObj.body.h1
except AttributeError as e:
return None
return title title = getTitle("http://www.pythonscraping.com/pages/page1.html")
if title == None:
print("Title could not be found")
else:
print(title)

  

Run:

python3 ./index.py

  <h1>An Interesting Title</h1>

* python库下载

https://www.lfd.uci.edu/~gohlke/pythonlibs/

pip3 install beautifulsoup4 出现错误 There was a problem confirming the ssl certificate的更多相关文章

  1. pip3 install jupyter出现错误

    问题描述 出现如下错误: Command "/Users/wang/.pyenv/versions/3.3.1/bin/python3.3 -u -c "import setupt ...

  2. PySpider 框架爬虫错误 HTTP 599: SSL certificate problem: unable to get local issuer certificate解决方案

    首先pyspider all启动pyspider的所有服务,然后访问http://localhost:5000创建一个爬虫任务:taobaomm,点开任务链接编辑http://localhost:50 ...

  3. python3安装pandas执行pip3 install pandas命令后卡住不动的问题及安装scipy、sklearn库的numpy.distutils.system_info.NotFoundError: no lapack/blas resources found问题

    一直尝试在python3中安装pandas等一系列软件,但每次执行pip3 install pandas后就卡住不动了,一直停在那,开始以为是pip命令的版本不对,还执行过 python -m pip ...

  4. Mac中 pip3 install mysqlclient 报错

    主要错误提示如下: ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use ...

  5. Ubuntu 18.04 + pip3 install virtualenvwrapper 找不到virtualenvwrapper.sh

    Reference Ubuntu 18.04 只自带python3.6.5, 因此不想装python2了, 但通过apt install 装virtualenvwrapper时发现必须得装python ...

  6. 安装tomcat出现failed to install tomcat8 service错误及解决方法

    failed to install tomcat8 service 如下图所示:     一.安装tomcat出现failed to install tomcat6 service错误及解决方法(转载 ...

  7. ubuntu,装完PYTHON3 pip3 install 报错

    ubuntu,装完PYTHON3 pip3  install 报错CalledProcessError: Command 'lsb_release -a' returned non-zero exit ...

  8. mac系统 pip3 install scrapy 失败 No local packages or working download links found for incremental>=16.10.1

    使用pip3 install scrapy命令之后,会出现如下问题: Collecting scrapy Downloading Scrapy-1.4.0-py2.py3-none-any.whl ( ...

  9. pip3 install mysqlclient 报错 “/bin/sh: 1: mysql_config: not found”的解决方法

    执行 sudo apt-get install libmysqlclient-dev, 然后执行 pip3 install mysqlclient 成功.

随机推荐

  1. 如何保证前端项目上线后的安全?webfunny已总结前端最关键的12大指标

    实时监控大屏   众所周知:实时流量大屏,是用来监控前端项目上线质量的. 如大家所知,监控系统会监控线上应用的各项指标,如:错误.白屏.耗时等等,但是仔细一想,即使有这些监控,我们也不一定能够保证线上 ...

  2. Java异常处理的两种方式以及自定义异常的使用方法

    异常 就是程序出现了不正常的情况 Error:严重问题,不需要处理 Exception:称为异常类,他表示程序本身可以处理的问题 RuntimeException:在编译期是不检查的,出现问题后,需要 ...

  3. SpringBoot和mybatis整合报错:Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 152; columnNumber: 10; 元素类型为 "mapper"

    很明显,报错是xml有问题,于是去检查,发现: 由于粗心,保存的时候,按的太频繁,多按了个s在里面,导致启动报错!

  4. open62541(opcua)传输延迟探索小记

    缘起 将open62541作为中间件使用代替自定义数据的RPC,client通过订阅valueChange来接收数据.使用时发现有一些问题: 前后两次产生的数据相同时,不会触发valueChange ...

  5. JAVA中的策略模式strategy

    原文出自:http://ttitfly.iteye.com/blog/136467 1. 以一个算术运算为例,传统做法为: java 代码 package org.common; public cla ...

  6. Java HdAcm1174

    空间一般直线的方程是:(x-x0)/a=(y-y0)/b=(z-z0)/c,这是一条过(x0,y0,z0),方向矢量为{a,b,c}的直线.假设已知点的坐标是A(e,f,g),过A点,且与{a,b,c ...

  7. 理解ASP.NET Core - [01] Startup

    注:本文隶属于<理解ASP.NET Core>系列文章,请查看置顶博客或点击此处查看全文目录 准备工作:一份ASP.NET Core Web API应用程序 当我们来到一个陌生的环境,第一 ...

  8. @ModelAttribute 与@InitBinder

    3.4.6 @ModelAttribute 注解 Mod lAttribut 通常作用在 Controller 的某个方法上,此方法会首先被调用, 井将方法 结果作为 Model 的属性 然后再调用对 ...

  9. 阿里云服务器,http免费转https详细教程

    1.搜ssl证书,点击立即购买 2.这里我们选择免费证书,点击右边立即购买,去支付 购买完成之后,申请证书状态会显示在审核中,不过很快的,几分钟就申请成功了,以下就是我申请成功的界面,因为我服务器用的 ...

  10. redhat9 linux 网卡无法激活排障

    先查看自己的系统版本! [root@localhost root]# uname -a Linux localhost 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 ...