A collection of search engine image scrapers (Google Images, DuckDuckGo and Brave) in C#.
See the examples folder for an example program.
A collection of search engine image scrapers (Google Images, DuckDuckGo and Brave)
License: MIT License
A collection of search engine image scrapers (Google Images, DuckDuckGo and Brave) in C#.
See the examples folder for an example program.
Hello,
As per this article from Microsoft https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines HttpClient
does not respect the IDisposable
interface. If this is used in Asp.Net it could lead to socket exhaustion from too many connections.
Basically the Scraper classes shouldn't implement IDisposable
and dispose of the HttpClient
, this is from the article listed above:
Any reasonably limited number of HttpClient instances will work as well. What matters here is that they are not created and disposed with each request as they each contain a connection pool. Using more than one instance is necessary for scenarios with multiple proxies or to separate cookie containers without completely disabling cookie handling.
Would you be open to a PR that would also add some interfaces to better use/register classes in ASP.net dependency injection container and removes this interface?
Here's some additional reading on how it's used in ASP.net =>https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-7.0#named-clients
code is here:
GoogleScraper GoogleScraper = new GoogleScraper();
IEnumerable images = await GoogleScraper.GetImagesAsync(query);
Random Random = new Random();
int image = Random.Next(0, images.Count());
message.Channel.SendMessage(images.ElementAt(image).Url);
i get this error:
GScraper.GScraperException: Failed to unpack the image object data.
---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'startIndex')
at System.String.IndexOf(Char value, Int32 startIndex, Int32 count)
at System.String.IndexOf(Char value, Int32 startIndex)
at GScraper.Google.GoogleScraper.ExtractDataPack(String page)
at GScraper.Google.GoogleScraper.GetImagesAsync(String query, SafeSearchLevel safeSearch, GoogleImageSize size, String color, GoogleImageType type, GoogleImageTime time, String license, String language)
--- End of inner exception stack trace ---
at GScraper.Google.GoogleScraper.GetImagesAsync(String query, SafeSearchLevel safeSearch, GoogleImageSize size, String color, GoogleImageType type, GoogleImageTime time, String license, String language)
at Ascension.โ .โซ.MoveNext()
if i use duckduckgoscraper this doesn't happen but duckduckgo returns irrelevant images quite a lot so i'd prefer if google worked
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.