Searching in Google with Python - Stack Overflow
Starting to learn Python in Google's Python Class - good idea?
In 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.
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>')
Hello! I'm an absolute beginner to programming, and thought I could start with the Goolge course on Python.
I've downloaded the zip with exercises, downloaded and installed Python and Notepad++, managed to set up Notepad as per the instructions, but I'm already stuck at the very beginning:
I'm supposed to run the following: C:\google-python-exercises> python hello.py
So, my first attempts were the following:
C:\google-python-exercises> python hello.py File "<stdin>", line 1 C:\google-python-exercises> python hello.py ^ SyntaxError: unexpected character after line continuation character
I've tried danielroseman's suggestion, and got the following:
python hello.py File "<stdin>", line 1 python hello.py ^ SyntaxError: invalid syntax
I've also tried kyber's suggestion, and this is the result:
python hello.py
File "<stdin>", line 1 python hello.py IndentationError: unexpected indent
And Python is supposed to print "Hello World", but I keep getting all kinds of errors. With the "unexpected character after line continuation charcter", I've figured it's because of backslash and the fact that is should be used to divide longer lines of code. I'm not sure what to do about the "unexpected indent". I've been running in circles and going crazy all evening :/ Is the course outdated or something? Was something new or different introduced in Py 3.12? If backslash is used to divide longer code, why use it here? What am I doing wrong? Is there any way around this?
Is Google's Python Class even a good idea to start with here?
Thanks!