Skip to content

Commit cdd885a

Browse files
init commit
1 parent 491a9e0 commit cdd885a

10 files changed

Lines changed: 169 additions & 2 deletions

File tree

.github/workflows/main.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: lint-test-publish
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Install dependencies
11+
run: |
12+
make deps
13+
- name: Lint code
14+
run: |
15+
make lint
16+
test:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
python-version: ['3.6', '3.7', '3.8']
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Set up Python
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
make deps
30+
publish:
31+
needs: [lint, test]
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: Install dependencies
36+
run: |
37+
make deps
38+
- name: Build package
39+
run: >-
40+
make build
41+
- name: Publish package to Test PyPI (always)
42+
uses: pypa/gh-action-pypi-publish@release/v1
43+
with:
44+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
45+
repository_url: https://test.pypi.org/legacy/
46+
skip_existing: true
47+
- name: Publish package to PyPI (only if pushing a tag)
48+
if: startsWith(github.ref, 'refs/tags')
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
password: ${{ secrets.PYPI_API_TOKEN }}

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
install: ## Install package from source in edit mode
2+
pip install -e .
3+
4+
deps: ## Install development dependencies
5+
pip install -r requirements.txt
6+
7+
lint: ## Lint code
8+
flake8 --config flake8 google_serp_api/ setup.py
9+
10+
build: ## Build a binary wheel and a source tarball
11+
python setup.py sdist bdist_wheel

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
1-
# google-serp-api-python
2-
Real-Time Google Search API
1+
# Google SERP API
2+
[Scrapeit Cloud](https://scrape-it.cloud/) - Web Scraping API with Proxy Rotation. Get valuable data at scale in HTML format from any website without need for a proxy.
3+
4+
Interface to call [Google SERP API](https://scrape-it.cloud/google-search-api/) easily from Python.
5+
6+
## Install
7+
8+
npm i @scrapeit-cloud/google-serp-api
9+
10+
## Usage
11+
Signup to Scrapeit Cloud to [get your API key](https://app.scrape-it.cloud/sign-up) and some free credits to get started.
12+
13+
>>> from google_serp_api import ScrapeitCloudClient
14+
>>>
15+
>>> client = ScrapeitCloudClient(api_key='INSERT_YOUR_API_KEY_HERE')
16+
>>>
17+
>>> response = client.scrape(
18+
params={
19+
"keyword": "pizza",
20+
"country": "US",
21+
"num_results": 10,
22+
"domain": "com"
23+
}
24+
)
25+
>>>
26+
>>> response.text
27+
'{"status":"ok","scrapingResult":{"currentPage":1,"keyword":"pizza","organic":[{"domain":"www.pizzahut.com","linkType":"HOME","position":1,"snippet":"DELIVERY & CARRYOUT LOCATIONS ARE OPEN! Order pizza online from a store near you. View our full menu, nutritional information, store locations, and more.Contact Us · School Lunch · Careers · Restaurant Careers","title":"Pizza Hut: Pizza Delivery | Pizza Carryout | Coupons | Wings & More","url":"https://www.pizzahut.com/","sitelinks":[{"href":"/url?q=https://www.pizzahut.com/contactus&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgJEAU&usg=AOvVaw1kJCddQOovwwu7D2ICu8XQ","title":"Contact Us","type":"INLINE"},{"href":"/url?q=https://www.pizzahut.com/school-lunch&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgJEAY&usg=AOvVaw1XreOmUmwdklpQ1qEFpg7R","title":"School Lunch","type":"INLINE"},{"href":"/url?q=https://jobs.pizzahut.com/&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgJEAc&usg=AOvVaw2o7KrOxIINSr_crNMhF0I7","title":"Careers","type":"INLINE"},{"href":"/url?q=https://jobs.pizzahut.com/restaurants/careers.php&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgJEAg&usg=AOvVaw2u8lAxbtm5KXVoz227oHME","title":"Restaurant Careers","type":"INLINE"}]},{"domain":"www.dominos.com","linkType":"LANDING","position":2,"snippet":"Order pizza, pasta, sandwiches & more online for carryout or delivery from Domino\'s. View menu, find locations, track orders. Sign up for Domino\'s email\xa0...About Pizza · Order Online · Coupons · Menu","title":"Domino\'s: Pizza Delivery & Carryout, Pasta, Chicken & More","url":"https://www.dominos.com/en/","sitelinks":[{"href":"/url?q=https://www.dominos.com/en/about-pizza/&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgKEAU&usg=AOvVaw0THBSmkvIM9dttcHmyQ-bL","title":"About Pizza","type":"INLINE"},{"href":"/url?q=https://www.dominos.com/en/pages/order/&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgKEAY&usg=AOvVaw3_zqtLbwr6oMEz91BKbP_6","title":"Order Online","type":"INLINE"},{"href":"/url?q=https://www.dominos.com/en/pages/order/coupon&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgKEAc&usg=AOvVaw3jxjpqTPqGZ75dqYTkE8Cc","title":"Coupons","type":"INLINE"},{"href":"/url?q=https://www.dominos.com/en/pages/order/menu&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q0gJ6BAgKEAg&usg=AOvVaw14skq9tuVEZRsrV_VfJGm6","title":"Menu","type":"INLINE"}]},{"domain":"wethepizza.com","linkType":"HOME","position":3,"snippet":"WE, THE PIZZA offers great pizza in Capitol Hill DC & Arlington VA. Enjoy our lunch specials, inspired wings with a handmade italian soda. Order Online Now!","title":"We The Pizza: WE, THE PIZZA | Restaurant & Delivery | Capitol Hill ...","url":"https://wethepizza.com/"},{"domain":"dc.eater.com","linkType":"LANDING","position":4,"snippet":"Jul 19, 2022 · Where to find wood-fired Neapolitan pizza, New York slices, Detroit-style squares, and free-form Roman pies.","title":"The Essential Pizza Restaurants in D.C. - Eater DC","url":"https://dc.eater.com/maps/best-pizza-restaurants-dc"},{"domain":"en.wikipedia.org","linkType":"LANDING","position":5,"snippet":"Pizza is a dish of Italian origin consisting of a usually round, flat base of leavened wheat-based dough topped with tomatoes, cheese, and often various\xa0...Place of origin: ItalyMain ingredients: Dough, sauce (usually tomato sauce), cheeseRegion or state: Campania (Naples)Course: Lunch or dinner","title":"Pizza - Wikipedia","url":"https://en.wikipedia.org/wiki/Pizza","sitelinks":[{"href":"/url?q=http://en.wikipedia.org/wiki/Italy&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Qs2Z6BAgCEAY&usg=AOvVaw0LM-l1Ht0MF11A9frBfnHO","title":"Italy","type":"INLINE"},{"href":"/url?q=http://en.wikipedia.org/wiki/Cheese&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Qs2Z6BAgCEAg&usg=AOvVaw0lO0X-QQyCDSAwJcTeZtKF","title":"cheese","type":"INLINE"},{"href":"/url?q=http://en.wikipedia.org/wiki/Campania&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Qs2Z6BAgCEAo&usg=AOvVaw1LfrqIRdlFczTJXAwViWxz","title":"Campania","type":"INLINE"},{"href":"/url?q=http://en.wikipedia.org/wiki/Naples&sa=U&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Qs2Z6BAgCEAs&usg=AOvVaw0_T-AY4SPJ8CSH1OADLjK5","title":"Naples","type":"INLINE"}]},{"domain":"www.papajohns.com","linkType":"HOME","position":6,"snippet":"Enjoy the ease of ordering delicious pizza for delivery or carryout from a Papa Johns near you. Start tracking the speed of your delivery and earn rewards\xa0...","title":"Papa Johns Pizza Delivery & Carryout - Best Deals on Pizza, Sides ...","url":"https://www.papajohns.com/"},{"domain":"m.yelp.com","linkType":"LANDING","position":7,"snippet":"Rating 4.0 (22,014) Best Pizza in Washington, DC - Wiseguy Pizza, il Canale, Pi Pizzeria, Andy\'s Pizza - Shaw, L\'Ardente, Pupatella, Lupo Pizzeria, Kouzina Angelinas Pizzeria\xa0...","title":"Pizza Washington, DC - Last Updated August 2022 - Yelp","url":"https://m.yelp.com/search?find_desc=Pizza&find_loc=Washington%2C+DC"},{"domain":"www.tripadvisor.com","linkType":"LANDING","position":8,"snippet":"Pizza Places in Washington DC ; 1. Pi Pizzeria · 1,286 reviews · “Beer not cold, although PIzza\'s lovely” ; 2. We the Pizza · 950 reviews · “Excellent pizza right\xa0...","title":"THE 10 BEST Pizza Places in Washington DC - TripAdvisor","url":"https://www.tripadvisor.com/Restaurants-g28970-c31-Washington_DC_District_of_Columbia.html"},{"domain":"www.franklypizza.com","linkType":"HOME","position":9,"snippet":"Hearth-baked pizza is our specialty. Our tiny kitchen leaves room for one thing, and that\'s pizza! Quickly baked in our oak-fired brick oven, pizzas emerge\xa0...","title":"Frankly…Pizza! - Kensington","url":"https://www.franklypizza.com/"},{"domain":"www.seriouseats.com","linkType":"LANDING","position":10,"snippet":"Our crisp, crunchy, chewy, and cheesy pizza recipes include everything from classic Neapolitan and New York pies to Sicilian and Detroit-style.","title":"Pizza Recipes - Serious Eats","url":"https://www.seriouseats.com/pizza-recipes-5117816"}],"pagination":[],"relatedKeywords":[{"keyword":"Pizza near me","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=Pizza+near+me&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEAI"},{"keyword":"Pizza Hut","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=Pizza+Hut&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEAQ"},{"keyword":"Pizza delivery near me","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=Pizza+delivery+near+me&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEAY"},{"keyword":"Pizza Domino","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=Pizza+Domino&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEAg"},{"keyword":"MOD Pizza","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=MOD+Pizza&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEAo"},{"keyword":"Pizza Hut near me","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=Pizza+Hut+near+me&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEAw"},{"keyword":"Pizza menu","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=Pizza+menu&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEA4"},{"keyword":"We The Pizza","path":"/search?cr=countryUS&hl=en&gl=US&ie=UTF-8&tbs=ctr:countryUS&q=We+The+Pizza&sa=X&ved=2ahUKEwiM0vD24775AhUBEmIAHbXIA54Q1QJ6BAgHEBA"}],"locals":[{"name":"Manhattan Pizza","position":1,"rating":"4.4","reviews":"552"},{"name":"Marco\'s Pizza","position":2,"rating":"4.4","reviews":"66"},{"name":"Emilio\'s Brick Oven Pizza","position":3,"rating":"4.3","reviews":"416"}]}}'
28+
>>>
29+
30+
You can find all the supported parameters on [Scrapeit Cloud documentation](https://scrape-it.cloud/docs/).

google_serp_api/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__all__ = ['ScrapeitCloudClient']
2+
3+
from google_serp_api.client import ScrapeitCloudClient

google_serp_api/__version__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.0.1'

google_serp_api/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from requests import request, Response
2+
3+
from .default_headers import default_headers
4+
5+
6+
class ScrapeitCloudClient:
7+
api_url = "https://api.scrape-it.cloud/scrape/google"
8+
9+
def __init__(self, api_key: str):
10+
self.api_key = api_key
11+
12+
def scrape(
13+
self,
14+
params: dict,
15+
**kwargs
16+
) -> Response:
17+
headers = {
18+
"x-api-key": self.api_key
19+
}
20+
21+
headers.update(default_headers)
22+
23+
return request("POST", self.api_url, data=params, headers=headers, **kwargs)

google_serp_api/default_headers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .__version__ import __version__
2+
3+
# Add User-Agent identifying sdk
4+
default_headers = {"User-Agent": f"ScrapeitCloud-Python/{__version__}"}

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flake8==3.9.2
2+
pytest==5.4.2
3+
tox==3.23.1
4+
wheel==0.36.2

setup.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
3+
from setuptools import setup
4+
5+
about = {}
6+
here = os.path.abspath(os.path.dirname(__file__))
7+
with open(os.path.join(here, 'google_serp_api', '__version__.py'), 'r', encoding='utf-8') as f:
8+
exec(f.read(), about)
9+
10+
setup(
11+
name='google-serp-api',
12+
version=about['__version__'],
13+
url='https://github.com/Scrapeit-Cloud/google-serp-api-python',
14+
description='Real-Time Google Search API',
15+
long_description=open('README.md').read(),
16+
long_description_content_type='text/markdown',
17+
author='Roman Milyushkevich',
18+
author_email='roman@scrape-it.cloud',
19+
maintainer='Roman Milyushkevich',
20+
maintainer_email='roman@scrape-it.cloud',
21+
license='MIT',
22+
packages=['google_serp_api'],
23+
classifiers=[
24+
'License :: OSI Approved :: MIT License',
25+
'Programming Language :: Python',
26+
'Programming Language :: Python :: 3',
27+
'Programming Language :: Python :: 3.6',
28+
'Programming Language :: Python :: 3.7',
29+
'Programming Language :: Python :: 3.8',
30+
'Topic :: Software Development :: Libraries :: Python Modules',
31+
],
32+
python_requires='>=3.6',
33+
install_requires=['requests'],
34+
)

tox.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tox]
2+
envlist = py36,py37,py38
3+
4+
[testenv]
5+
allowlist_externals = make
6+
deps = pytest
7+
commands =
8+
make test

0 commit comments

Comments
 (0)