python - 为什么我在输入 url 后得到一个回溯说“无效参数”?
问题描述
输入的文件名:http://www.dr-chuck.com
Traceback (most recent call last):
File "C:\Users\Sree\Desktop\py4e\crawl.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
File "C:\Users\Sree\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 86, in <module>
import email
File "C:\Users\Sree\Desktop\py4e\email.py", line 2, in <module>
fh = open(fname)
OSError: [Errno 22] Invalid argument: 'http://www.dr-chuck.com'
我输入的任何网址都被视为无效参数!请帮忙!
import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = input('Enter: ')
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, 'html.parser')
# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
print(tag.get('href', None))
解决方案
推荐阅读
- azure-resource-manager - Azure Api Management 使用 arm 将 api 附加到现有 api
- c# - 单击按钮时如何在面板中加载用户组件?
- javascript - 从日期“2019-06-29T 1:25:40,000 + 00:00”中提取小时数并将其计算为“1h 25 min 40 sec”
- javascript - 如何在没有任何缓冲区错误的情况下检索 JSON 密钥?
- go - 为什么 Go-get 要求我选择一个分支?
- php - 我想把购物车页面的组合框改成文本框
- timeout - Keycloak4.7.0 final 中用户注册表单的 Recaptcha 不起作用
- odoo-11 - 我收到一个错误:连接测试失败!这是我们得到的结果:-3 名称解析暂时失败
- html - 防止 flex PARENT 在没有溢出的情况下增长:隐藏
- python - RemoveError: 'pyopenssl' 是 conda 的依赖,不能从 conda 的运行环境中移除