Question: Python google search with urllib: I am working on a program where the user can input a search term and search google using urllib. The
Python google search with urllib:
I am working on a program where the user can input a search term and search google using urllib. The program seems to be stopping at this line but I am not sure why:
req = urllib.request.Request(url, None, headers)
with the error:
Traceback (most recent call last): File "C:\Users\Kristen Albrecht\OneDrive\Joint Documents\Education\UCLA Applications Programing\Python\Week 7\KristenAlbrechtProject7\google.py", line 19, in
_____________________________________________________
goolge.py
import urllib.request
def main(): term = input('Enter a search term: ') url = 'http//www.google.com/search' value = {'q' : term} user_agent = 'Mozilla/5.0' headers = {'User-Agent' : user_agent} data = urllib.parse.urlencode(value) print(data) url = url + '?' + data print(url) req = urllib.request.Request(url, None, headers) response = urllib.request.urlopen(req) html = response.read() print(html) main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
