我试图使用来自Github(https://github.com/gto76/betbrain-scraper)的betbrain.py,其中包含以下代码:
#!/usr/bin/python3
#
# Usage: betbrain.py [URL or FILE] [OUTPUT-FILE]
# Scrapes odds from passed betbrain page and writes them to
# stdout, or file if specified.
import os
import sys
import urllib.request
from bs4 import BeautifulSoup
from http.cookiejar import CookieJar
import parser_betbrain
import printer
DEFAULT_URL = 'https://www.betbrain.com/football/england/premier-league/#!/matches/'
# If no arguments are present, it parses the default page.
# Argument can be an URL or a local file.
def main():
html = getHtml(sys.argv)
soup = BeautifulSoup(html, "html.parser")
matches = parser_betbrain.getMatches(soup)
string = printer.matchesToString(matches)
output(string, sys.argv)
def getHtml(argv):
if len(argv) <= 1:
return scrape(DEFAULT_URL)
elif argv[1].startswith("http"):
return scrape(argv[1])
else:
return readFile(argv[1])
# Returns html file located at URL.
def scrape(url):
cj = CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
try:
return opener.open(url)
except ValueError:
error("Invalid URL: " + url)
def readFile(path):
try:
return open(path, encoding='utf8')
except IOError:
error("Invalid input filename: " + path)
def output(string, argv):
if len(argv) <= 2:
print(string)
else:
writeFile(argv[2], string)
def writeFile(path, string):
try:
fo = open(path, "w", encoding='utf8')
fo.write(string);
fo.close()
except IOError:
error("Invalid output filename: " + path)
def error(msg):
msg = os.path.basename(__file__)+": "+msg
print(msg, file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
main()
但是,当运行时,它会返回此错误
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py", line 71, in <module>
main()
File "/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py", line 22, in main
html = getHtml(sys.argv)
File "/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py", line 30, in getHtml
return scrape(DEFAULT_URL)
File "/Users/Daniel/Desktop/betbrain-scraper-master 2/betbrain.py", line 41, in scrape
return opener.open(url)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
我怎样才能解决这个问题?我在MacOS 10.12.1上运行Python 3.6.0
在CentOS Linux上,Python3。我编辑了这个文件(先备份一份)
/usr/lib/python3.6/site-packages/certifi/cacert.pem
在文件的末尾,我添加了我的公共证书。pem文件。您应该能够获得。来自ssl证书提供商的pem文件。
我在MacOS/Applications/Python\3.6/Install\Certificates上运行了这个。命令
打开终端并查看:
/Applications/Python 3.6/Install Certificates.command
MacOS上的Python3.6使用嵌入式版本的OpenSSL,它不使用系统证书存储。这里有更多细节。
(明确地说:MacOS用户可能可以通过打开Finder并双击Install Certificates.command来解决)
- 我运行了此脚本,但出现了此错误。我怎么做?
我不能通过pip安装安装任何外部python模块。我已经正确安装了python,但如果我使用pip_install它显示我这个错误。 下面是我运行
问题内容: 我无法通过pip install安装任何外部python模块。我已经正确安装了python,但是如果我使用pip_install,它将显示此错误。 这是我运行后的代码 我该如何解决这个问题? 我可以使用此命令部分解决问题 但是我在这里找不到此问题建议的计算机上的任何pip.ini文件夹 有任何永久解决此问题的建议吗? 问题答案: 当我在需要外部网络访问权限代理的公司网络中时,我遇到了类
问题内容: 尝试运行Discord机器人时,遇到此错误: 它刚刚开始无处不在,并且每次都在发生。 我在Windows 10上使用python 3.8 这是什么意思,我该如何解决? 问题答案: 要解决此问题: 使用Internet Explorer转到discord.com(以管理员身份运行) 点击右上角的锁 点击查看证书 安装一个 PS:如果您的防病毒软件对Web浏览器有效,并且此解决方案不起作用
您好,我在构建python映像时遇到问题 错误说, 但是当升级pip时,同样的错误显示。 错误:由于环境原因无法安装程序包错误:HTTPSConnectionPool(host='files.pythonhosted.org',port=443):url超过最大重试次数:/packages/ac/cf/0cc542fc93de2f3b9b53cb979c7d118cffb93204afb4629a
问题内容: 尝试上使用。 无论软件包如何,pip安装都会失败。例如,还会导致SSL错误。 原始安装的Python 3.4.1包含pip 1.5.6。我尝试做的第一件事是安装已经安装,它是ArcGIS附带的。python并且pip直到我安装3.4.1时才可从命令行使用。 作品。可能是因为点子搜索无法验证站点的SSL证书。 我在公司网络中,但是我们不通过代理访问Internet。 每台公司计算机(包括