Google Image Scraper.
Project description
Google-Image-Scraper
About
This module is based on web-scraping technology and uses Google Images to provide a Streamable Image API.
Supported Browsers
- Chrome
How to Use?
# import Scraper class
from gi_scraper import Scraper
# Pass a Cache instance with a custom directory path and timeout
# Set cache timeout to -1 for caching indefinitely
"""
from gi_scraper import Cache
cache = Cache(dir_path="gi_cache", timeout=-1)
sc = Scraper(workers=8, headless=False, cache=cache)
"""
# The object creation has an overhead time
# The same object can be reused to fire multiple queries
sc = Scraper(headless=False)
for query, count in {"Naruto": 20, "Gintoki": 30}.items():
print("Scraping...", query, ":", count)
# scrape method returns a stream object
stream = sc.scrape(query, count)
# stream.get method yields Response object with following attributes
# - query (str): The query associated with the response.
# - name (str): The name attribute of the response.
# - src_name (str): The source name attribute of the response.
# - src_page (str): The source page attribute of the response.
# - thumbnail (str): The thumbnail attribute of the response.
# - image (str): The image attribute of the response.
# - width (int): The width attribute of the response.
# - height (int): The height attribute of the response.
for index, response in enumerate(stream.get()):
if index == 10:
sc.terminate_query() # Terminate current query midway
break
# response.to_dict returns python representable dictionary
print(response.width, "x", response.height, ":", response.image)
# call this to terminate scraping (auto-called by destructor)
sc.terminate()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gi_scraper-0.4.6.tar.gz
(9.0 kB
view hashes)
Built Distribution
Close
Hashes for gi_scraper-0.4.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67f42deb3b5b4898c2169e11a98416322eaff626b3931432a046aa072d519bba |
|
MD5 | 318d088fbd05da23c5439b41666c8d70 |
|
BLAKE2b-256 | c862e1928081d14a1b8539ca236c28b5e020f69217656b3e2006346b184b19c4 |