我已经使用'pip install requests'
安装了请求,但我没有得到任何返回。
我正在遵循基本 tutorial 中给出的示例并在此代码
上不断收到此错误
:
from bs4 import BeautifulSoup
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=47.19044000000008&lon=-122.29563999999999#.Xq3cLZl7lPY')
soup = BeautifulSoup(page.content, 'html-parser')
print(soup)
和错误
:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-90e58007c1ee> in <module>
1 from bs4 import BeautifulSoup
----> 2 page = requests.get('https://forecast.weather.gov/MapClick.php?lat=47.19044000000008&lon=-122.29563999999999#.Xq3cLZl7lPY')
3 soup = BeautifulSoup(page.content, 'html-parser')
4 print(soup)
NameError: name 'requests' is not defined
最佳答案
我认为,您需要导入请求
。你可以尝试一下:
from bs4 import BeautifulSoup
import requests
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=47.19044000000008&lon=-122.29563999999999#.Xq3cLZl7lPY')
soup = BeautifulSoup(page.text, 'lxml')
print(soup)
关于python - 安装请求后(使用 JupyterLab),获取 "NameError: name ' 请求未定义”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61566552/