MissingSchema: Invalid URL 'h': No schema supplied. Perhaps you meant http://h?

Question:

I have been trying to scrape addresses and Phone numbers from google for different business names, my code works fine when I give a URL, it fetches the required info. But when I tried to loop I’m getting the below error.

 MissingSchema: Invalid URL 'h': No schema supplied. Perhaps you meant http://h?

but the same URL works fine as shown below!

url = 'https://www.google.com/search?q=goinggourmet'
response = requests.get(url, {"User-Agent": ua.random})
print(Address)

This is code that raised an error while looping

bus_name = ['go', 'Copper']
for names in bus:
    html= urllib.parse.quote_plus(names)
    for url in google_urls:
        response = requests.get(url, {"User-Agent": ua.random})
Asked By: Ahina7

||

Answers:

Because you create google_urls as a string before iterating, the for loop iterates over the characters in it instead

>>> for value in "http":  # iterates over characters
...     print(value)
...
h
t
t
p
>>> for value in ["http"]:  # iterates over a list with 1 member
...     print(value)
...
http
Answered By: ti7