Comments (6)
Why do you a errChan channel
?
Is it correct to do this?
go func() {
defer c.wg.Done()
errChan := c.scrape(...)
// Do some stuff ....
}()
from colly.
Why do you a errChan channel?
I use it here to let caller wait for an error on that channel.
errChan := scrapeAsync(...)
... do stuff ...
err := <-errChan
Is it correct to do this?
It depends on what are you going to do with that error (c.scrape(...)
returns error
).
from colly.
@THE108 you are right, the current behavior is not suitable for your needs. As a workaround you can wrap c.Visit
with a function and use a WaitGroup there.
The func (c *Collector) scrapeAsync(...) chan<- error
approach is interesting, how do you imagine the public API for this? Duplicating all the Visit
, Post
, PostRaw
, etc.. functions of the Collector
and the Request
with an Async
prefix wouldn't be the best..
Perhaps Collector
could be extended with an Async bool
member and if Collector.Async
is true
then scrapeAsync
would be called instead of scrape
. With this solution it is not possible to return an error channel, this is the only downside, but errors can be handled in OnError
callbacks. What do you think?
from colly.
I think it's better to add new functionality than changing existing one (breaking back compatibility).
Anyway, I think both options are not perfect. So, maybe we can think about:
-
Let caller manage concurrency themselves. Just provide a
sync.WaitGroup
as a param (possiblynil
). -
Manage concurrency internally.
Collector
could handle its own goroutine pool (which will provide better goroutine reuse and request rate limiting).
from colly.
I think it's better to add new functionality than changing existing one (breaking back compatibility).
The solution I suggested doesn't break the existing api.
from colly.
Sorry, I misunderstood your suggestion.
Perhaps Collector could be extended with an
Async bool
member and ifCollector.Async
is true thenscrapeAsync
would be called instead ofscrape
.
I think that should work.
from colly.
Related Issues (20)
- Fetching data that is not coming in curl output HOT 1
- SIGSEG on local files HOT 1
- Misleading Request.Depth documentation HOT 1
- I have a request that I don't know how to make using Colly. HOT 1
- Different MaxDepth on AllowedDomains and others ? HOT 3
- Is there a way spider for "https://netbanking.hdfcbank.com/netbanking" with my owner account? HOT 1
- HTML encoding is not autodetected properly HOT 6
- request chan error HOT 1
- Cannot send request with no Accept header HOT 1
- handleOnXML tries to parse`.xlsx` files HOT 2
- Next release - When?
- Duplicated requests HOT 1
- How to handle selector not found?
- how to by pass c.OnError HOT 1
- Post Login not persist session
- Weird async behaviour - duplicates in responses HOT 1
- Support BFS search .
- retry redirect to AlreadyVisitedUrl will loop error HOT 1
- Error trying to conditionally set up proxy function HOT 1
- Can't provide duplicate key values when POSTing form data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colly.