Getting "NameError: name 'requests' is not defined" after already installing requests (using JuypterLab)
Getting "NameError: name 'requests' is not defined" after already installing requests (using JuypterLab)
我已经使用 'pip install requests'
安装了请求,但我什么也没得到。
我正在按照基本 tutorial 中给出的示例进行操作,并在 code
:
上继续获取此 error
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)
和 error
:
---------------------------------------------------------------------------
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
我认为,你需要import requests
。你可以试试:
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)
我已经使用 'pip install requests'
安装了请求,但我什么也没得到。
我正在按照基本 tutorial 中给出的示例进行操作,并在 code
:
error
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)
和 error
:
---------------------------------------------------------------------------
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
我认为,你需要import requests
。你可以试试:
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)