From b040b24a70ffc42740bbd1c7711fedecdd5bcfa5 Mon Sep 17 00:00:00 2001 From: Rustem Kamalov Date: Sun, 6 Aug 2023 15:09:26 +0300 Subject: [PATCH] Readme update --- README.md | 37 ++++++++++++++++++++++++++++--------- google/search.go | 4 +++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 44f9d1a..2d4f7e0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ API access for search engines results if available isn't free. Using OpenSERP, you can get search results from **Google**, **Yandex**, **Baidu** via API or CLI! -See [Docker](#docker) and [CLI](#cli) usage examples below. +See [Docker](#docker) and [CLI](#cli) usage examples below ([search](#search), [images](#images)). ## Docker usage 🐳 * Run API server: @@ -21,13 +21,6 @@ docker run -p 127.0.0.1:7000:7000 -it karust/openserp serve -a 0.0.0.0 -p 7000 docker-compose up --build ``` -### *Example request* -Get 20 **Google** results for `hello world`, only in English: -``` -GET http:/127.0.0.1:7000/google/search?lang=EN&limit=20&text=hello world -``` -You can replace `google` to `yandex` or `baidu` in query to change search engine. - ### Request parameters | Param | Description | |-------|--------------------------------------------------------------| @@ -36,8 +29,34 @@ You can replace `google` to `yandex` or `baidu` in query to change search engine | date | Date in `YYYYMMDD..YYYYMMDD` format (e.g. 20181010..20231010) | | file | File extension to search (e.g. `PDF`, `DOC`) | | site | Search within a specific website | -| limit | Limit the number of results | +| limit | Limit the number of results +### **Search** +### *Example request* +Get 20 **Google** results for `hello world`, only in English: +``` +GET http:/127.0.0.1:7000/google/search?lang=EN&limit=20&text=hello world +``` +You can replace `google` to `yandex` or `baidu` in query to change search engine. + | + +### *Example response* +```JSON +[ + { + "rank": 1, + "url": "https://en.wikipedia.org/wiki/%22Hello,_World!%22_program", + "title": "\"Hello, World!\" program", + "description": "A \"Hello, World!\" program is generally a computer program that ignores any input, and outputs or displays a message similar to \"Hello, World!\"." + }, +] +``` +### **Images** +### *Example request* +Get 100 **Google** results for `golden puppy`: +``` +GET http://127.0.0.1:7000/google/image?text=golden puppy&limit=100 +``` ### *Example response* ```JSON [ diff --git a/google/search.go b/google/search.go index 707f931..731ed55 100644 --- a/google/search.go +++ b/google/search.go @@ -216,7 +216,7 @@ func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) { continue } - for i, r := range resultElements[len(searchResultsMap):] { + for i, r := range resultElements { // TODO: parse AF_initDataCallback to optimize instead of this? err := r.Click(proto.InputMouseButtonRight, 1) if err != nil { @@ -271,6 +271,8 @@ func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) { Description: fmt.Sprintf("Height:%v, Width:%v, Source Page: %v", imgSrc.Height, imgSrc.Width, imgSrc.PageURL), } searchResultsMap[*dataID] = gR + + r.Remove() } if !gogl.LeavePageOpen {