NameError: name 'requests' is not defined [closed]
I have taken this code as for help "Python getting all links from a google search result page" .
When I try importing requests in Python 3.3.3, I get NameError: name 'requests' is not defined
. I tested the "request" and "bs4" module using the CMD prompt and both show that this library has been installed.
I am trying to extract the related searched links from Google Search Result, but I don't know why I'm getting this error.
from bs4 import BeautifulSoup
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
import re
links = soup.findAll("a")
for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")):
print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
Error: Traceback (most recent call last):
File "C:/Users/DELL/Desktop/python/s/beauti.py", line 2, in <module>
page = requests.get("https://www.google.dz/search?q=see")
NameError: name 'requests' is not defined
python compiler-errors python-import
closed as off-topic by Padraic Cunningham, Charles Duffy, senshin, Greg, ivan_pozdeev Nov 12 '14 at 23:41
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Charles Duffy, senshin, Greg, ivan_pozdeev
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have taken this code as for help "Python getting all links from a google search result page" .
When I try importing requests in Python 3.3.3, I get NameError: name 'requests' is not defined
. I tested the "request" and "bs4" module using the CMD prompt and both show that this library has been installed.
I am trying to extract the related searched links from Google Search Result, but I don't know why I'm getting this error.
from bs4 import BeautifulSoup
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
import re
links = soup.findAll("a")
for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")):
print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
Error: Traceback (most recent call last):
File "C:/Users/DELL/Desktop/python/s/beauti.py", line 2, in <module>
page = requests.get("https://www.google.dz/search?q=see")
NameError: name 'requests' is not defined
python compiler-errors python-import
closed as off-topic by Padraic Cunningham, Charles Duffy, senshin, Greg, ivan_pozdeev Nov 12 '14 at 23:41
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Charles Duffy, senshin, Greg, ivan_pozdeev
If this question can be reworded to fit the rules in the help center, please edit the question.
1
If you never ranimport requests
, why would you expect the namerequests
to mean anything? (Given that it's not given in docs.python.org/2/library/functions.html, which is where the very limited set of builtins are listed).
– Charles Duffy
Nov 12 '14 at 21:20
add a comment |
I have taken this code as for help "Python getting all links from a google search result page" .
When I try importing requests in Python 3.3.3, I get NameError: name 'requests' is not defined
. I tested the "request" and "bs4" module using the CMD prompt and both show that this library has been installed.
I am trying to extract the related searched links from Google Search Result, but I don't know why I'm getting this error.
from bs4 import BeautifulSoup
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
import re
links = soup.findAll("a")
for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")):
print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
Error: Traceback (most recent call last):
File "C:/Users/DELL/Desktop/python/s/beauti.py", line 2, in <module>
page = requests.get("https://www.google.dz/search?q=see")
NameError: name 'requests' is not defined
python compiler-errors python-import
I have taken this code as for help "Python getting all links from a google search result page" .
When I try importing requests in Python 3.3.3, I get NameError: name 'requests' is not defined
. I tested the "request" and "bs4" module using the CMD prompt and both show that this library has been installed.
I am trying to extract the related searched links from Google Search Result, but I don't know why I'm getting this error.
from bs4 import BeautifulSoup
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
import re
links = soup.findAll("a")
for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")):
print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
Error: Traceback (most recent call last):
File "C:/Users/DELL/Desktop/python/s/beauti.py", line 2, in <module>
page = requests.get("https://www.google.dz/search?q=see")
NameError: name 'requests' is not defined
python compiler-errors python-import
python compiler-errors python-import
edited Oct 17 '17 at 14:40
Steven M. Vascellaro
6,04694395
6,04694395
asked Nov 12 '14 at 19:52
user3440716user3440716
1962315
1962315
closed as off-topic by Padraic Cunningham, Charles Duffy, senshin, Greg, ivan_pozdeev Nov 12 '14 at 23:41
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Charles Duffy, senshin, Greg, ivan_pozdeev
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Padraic Cunningham, Charles Duffy, senshin, Greg, ivan_pozdeev Nov 12 '14 at 23:41
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Charles Duffy, senshin, Greg, ivan_pozdeev
If this question can be reworded to fit the rules in the help center, please edit the question.
1
If you never ranimport requests
, why would you expect the namerequests
to mean anything? (Given that it's not given in docs.python.org/2/library/functions.html, which is where the very limited set of builtins are listed).
– Charles Duffy
Nov 12 '14 at 21:20
add a comment |
1
If you never ranimport requests
, why would you expect the namerequests
to mean anything? (Given that it's not given in docs.python.org/2/library/functions.html, which is where the very limited set of builtins are listed).
– Charles Duffy
Nov 12 '14 at 21:20
1
1
If you never ran
import requests
, why would you expect the name requests
to mean anything? (Given that it's not given in docs.python.org/2/library/functions.html, which is where the very limited set of builtins are listed).– Charles Duffy
Nov 12 '14 at 21:20
If you never ran
import requests
, why would you expect the name requests
to mean anything? (Given that it's not given in docs.python.org/2/library/functions.html, which is where the very limited set of builtins are listed).– Charles Duffy
Nov 12 '14 at 21:20
add a comment |
1 Answer
1
active
oldest
votes
install requests
pip install requests
and change your code like this:
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
links = soup.findAll("a")
for link in links:
if link['href'].startswith('/url?q='):
print (link['href'].replace('/url?q=',''))
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
you must first installpip
, and installrequests
via pip
– Hasan Ramezani
Nov 12 '14 at 20:00
|
show 9 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
install requests
pip install requests
and change your code like this:
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
links = soup.findAll("a")
for link in links:
if link['href'].startswith('/url?q='):
print (link['href'].replace('/url?q=',''))
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
you must first installpip
, and installrequests
via pip
– Hasan Ramezani
Nov 12 '14 at 20:00
|
show 9 more comments
install requests
pip install requests
and change your code like this:
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
links = soup.findAll("a")
for link in links:
if link['href'].startswith('/url?q='):
print (link['href'].replace('/url?q=',''))
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
you must first installpip
, and installrequests
via pip
– Hasan Ramezani
Nov 12 '14 at 20:00
|
show 9 more comments
install requests
pip install requests
and change your code like this:
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
links = soup.findAll("a")
for link in links:
if link['href'].startswith('/url?q='):
print (link['href'].replace('/url?q=',''))
install requests
pip install requests
and change your code like this:
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.google.dz/search?q=see")
soup = BeautifulSoup(page.content)
links = soup.findAll("a")
for link in links:
if link['href'].startswith('/url?q='):
print (link['href'].replace('/url?q=',''))
edited Nov 12 '14 at 21:11
answered Nov 12 '14 at 19:54
Hasan RamezaniHasan Ramezani
3,7181224
3,7181224
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
you must first installpip
, and installrequests
via pip
– Hasan Ramezani
Nov 12 '14 at 20:00
|
show 9 more comments
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
you must first installpip
, and installrequests
via pip
– Hasan Ramezani
Nov 12 '14 at 20:00
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
is pip install requests also library?
– user3440716
Nov 12 '14 at 19:56
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
i have placed in this way: import requests from bs4 import BeautifulSoup page = requests.get("google.dz/search?q=see") soup = BeautifulSoup(page.content) links = soup.findAll("a") for link in soup.find_all("a",href=re.compile("(?<=/url?q=)(htt.*://.*)")): print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
– user3440716
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
no,pip is a package management system used to install and manage software packages written in Python
– Hasan Ramezani
Nov 12 '14 at 19:58
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
i have written in this way but nt giving me links, so i have to install pip?
– user3440716
Nov 12 '14 at 19:59
you must first install
pip
, and install requests
via pip– Hasan Ramezani
Nov 12 '14 at 20:00
you must first install
pip
, and install requests
via pip– Hasan Ramezani
Nov 12 '14 at 20:00
|
show 9 more comments
1
If you never ran
import requests
, why would you expect the namerequests
to mean anything? (Given that it's not given in docs.python.org/2/library/functions.html, which is where the very limited set of builtins are listed).– Charles Duffy
Nov 12 '14 at 21:20