-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #4 file with basic example added.
- Loading branch information
1 parent
d67a0e0
commit f124578
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/johnny-debt/instascrap" | ||
"golang.org/x/net/proxy" | ||
) | ||
|
||
// Provides default HTTP client (you can add proxy here or anything else) | ||
func customHTTPClientProvider() *http.Client { | ||
// create http.Client with proxy | ||
dialer, err := proxy.SOCKS5("tcp", "111.231.88.18:1080", nil, proxy.Direct) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "can't connect to the proxy:", err) | ||
os.Exit(1) | ||
} | ||
httpTransport := &http.Transport{} | ||
httpTransport.Dial = dialer.Dial | ||
httpClient := &http.Client{Transport: httpTransport} | ||
return httpClient | ||
} | ||
|
||
func main() { | ||
is := instascrap.NewInstascrap(customHTTPClientProvider) | ||
fmt.Printf("Instascrap created: %v\n", is) | ||
getHashtagMediaExample(is) | ||
} | ||
|
||
// Retrieves medias list | ||
func getHashtagMediaExample(is instascrap.Instascrap) { | ||
medias, err := is.GetHashtagMedia("golang") | ||
if err != nil { | ||
fmt.Printf("Medias retrieving failed, %s\n", err) | ||
return | ||
} | ||
fmt.Printf("Medias retrieved successfully. Count: %d", len(medias)) | ||
} |