NameError: the name "queries" is not defined

I used this code for Python help , getting all the links from the Google search results page .

When I try to import queries in Python 3.3.3, I get NameError: name 'requests' is not defined. I tested the request and bs4 modules using the CMD prompt, and both show that this library is installed.

I am trying to retrieve related search links from a Google Search Result, but I don’t know why I am 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
+4
source share
1 answer

to establish requests

pip install requests

and change your code as follows:

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=',''))
+9
source

All Articles