I assume you are using this library by Mario Vilas because of the stop=20 argument which appears in his code. It seems like this library is not able to return anything but the URLs, making it horribly undeveloped. As such, what you want to do is not possible with the library you are currently using.
I would suggest you instead use abenassi/Google-Search-API. Then you can simply do:
from google import google
num_page = 3
search_results = google.search("This is my query", num_page)
for result in search_results:
print(result.description)
Answer from Jokab on Stack OverflowIn light of the news about the python team at google
I thought I just sucked at learning python, but it turned out the Coursera Google Python course just sucks.
Why did Google choose Python?
Trouble getting past the first line of Google's Python class...
Did you notice that your prompt changed from students-MacBook-Pro:~ student$ to >>>? That's because you ran python by itself, which starts Python in interactive mode. When you see the >>> prompt, you are "in" the Python interpreter, and the things you type are interpreted directly by Python (and so must be valid Python syntax). When you have the students-MacBook-Pro:~ student$ prompt, you are giving commands to Bash (the shell, the program which always runs in the terminal and interprets the commands you type). If you have the Python prompt and you want to return to Bash, type Ctrl+D, or type exit() and hit enter.
In the prompt students-MacBook-Pro:~ student$, the first bit is your computer's hostname (students-MacBook-Pro), the bit after the colon is the name of the directory you are currently in (~), and the bit after that (I'm guessing) is your username (student). (And the $ is just a standard prompt ending.)
~ means your home directory, which on a Mac expands something like /Users/<username>. You can type the command pwd to see the full path of the current directory.
Use the command ls to list the files in your current directory. You'll find that hello.py is not one of them, hence the "No such file or directory" error. Python will only see files in your current directory.
So to run hello.py, you need to either move to the directory that contains it and then run python hello.py, or you can type out the full path instead of just hello.py. For example, if hello.py is inside a folder called exercises which is on your desktop, then you could run it by typing python Desktop/exercises/hello.py or by doing cd Desktop/exercises (cd stands for change directory) followed by python hello.py.
Videos
I assume you are using this library by Mario Vilas because of the stop=20 argument which appears in his code. It seems like this library is not able to return anything but the URLs, making it horribly undeveloped. As such, what you want to do is not possible with the library you are currently using.
I would suggest you instead use abenassi/Google-Search-API. Then you can simply do:
from google import google
num_page = 3
search_results = google.search("This is my query", num_page)
for result in search_results:
print(result.description)
Not exactly what I was looking for, but I found myself a nice solution for now (I might edit this if I will able to make this better). I combined searching in Google like I did (returning only URL) and the Beautiful Soup package for parsing HTML pages:
from googlesearch import search
import urllib
from bs4 import BeautifulSoup
def google_scrape(url):
thepage = urllib.urlopen(url)
soup = BeautifulSoup(thepage, "html.parser")
return soup.title.text
i = 1
query = 'search this'
for url in search(query, stop=10):
a = google_scrape(url)
print str(i) + ". " + a
print url
print " "
i += 1
This gives me a list of the title of pages and the link.
And another great solutions:
from googlesearch import search
import requests
for url in search(ip, stop=10):
r = requests.get(url)
title = everything_between(r.text, '<title>', '</title>')
» pip install googlesearch-python
» pip install google
If you hadn't heard, google let go it's entire python development team. Posts in r/programming and others made the rounds and lots of discussion ensued.
What caught my attention were a few comments about the maintenance required to keep python code running. In one case, C++ was mentioned as being more performant and having better longevity even with the C++ extensibility within python. I'm wondering where this discussion would fall within a dataengineering-centric community. I'm on mobile otherwise I'd put all the links I've come across in the last few days of reading.
Edit: I really appreciate the contributions & conversations. I'm seeing quite a few people doing many of the same things I have been doing, especially in the realms of mypy, pytest, pydocstyle, pylint, etc. To reiterate, the purpose of my post is less about corporate shenanigans and more about identifying & discussing non-python value in the DE ecosystem.