MissingSchema Traceback (most recent call last) Cell In[7], line 33 26 headers={ 27 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.1.4031 SLBChan/105', 28 }#设置请求头. 30 url='https://www.cobases.com/' ---> 33 print(get_base_area(url,headers)) Cell In[7], line 24, in get_base_area(url, headers) 22 s1=r'https://www.cobases.com/.*?/' 23 print(re.findall(s1,ws)[0]) ---> 24 return get_detail_area(ws[0],headers) Cell In[7], line 6, in get_detail_area(url, headers) 5 def get_detail_area(url,headers): ----> 6 r=requests.get(url,headers=headers) 7 r.raise_for_status() 8 r.encoding=r.apparent_encoding #解决乱码问题 File c:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py:73, in get(url, params, **kwargs) 62 def get(url, params=None, **kwargs): 63 r"""Sends a GET request. 64 65 :param url: URL for the new :class:`Request` object. ... 442 ) 444 if not host: 445 raise InvalidURL(f"Invalid URL {url!r}: No host supplied") MissingSchema: Invalid URL '<': No scheme supplied. Perhaps you meant https://<?
时间: 2024-04-02 22:33:40 浏览: 125
linux 下 pip3 报错“ File “/usr/bin/pip3”, line 9, in from pip import mainImportError: canno”处理
5星 · 资源好评率100%
这个错误提示是因为在调用`get_base_area`函数时,传入的`url`参数格式不正确,缺少了协议头(http或https),导致requests库无法识别这个URL,从而报错。你需要检查一下`url`参数的传入是否正确,如果确保了URL格式的正确性,可以考虑加上异常处理来避免这种错误的发生,例如:
```python
def get_base_area(url, headers):
try:
r = requests.get(url, headers=headers)
r.raise_for_status()
ws = r.text
s1 = r'https://www.cobases.com/.*?/'
print(re.findall(s1, ws)[0])
return get_detail_area(re.findall(s1, ws)[0], headers)
except requests.exceptions.RequestException as e:
print(e)
return None
```
在这个例子中,我们使用了try-except语句来捕获requests请求发生的异常,并将异常信息打印出来。这样可以帮助我们更好地定位问题所在。
阅读全文