r/webscraping • u/Fapient • 4d ago
Bot detection 🤖 How to scale without direct requests?
Hi,
The websites I am trying to scrape have bot detection requiring me to use a real stealthy browser and simulate human behaviour, however, this consumes a great of CPU and GPU on my local machine during testing, which doesn't seem very scalable to a VPS as that will likely be entirely CPU rendered to save costs.
I reuse a single instance and spawn isolated contexts to ease the RAM and CPU load, but this is only a minor saving in the grand scheme of things. I can't disable some rendering features or block certain things from loading because that would just increase the likelihood of being detected as a bot.
I am aware of session and cookie reuse with direct requests, but this doesn't help much as the bot detection requires continuous input for them to stay valid.
Does anyone else who runs stealthy browsers have any suggestions on how to scale this up to a cost effective VPS? Or share how many contexts a VPS can realistically handle at scale?
Thanks.
5
u/Tiny_Arugula_5648 4d ago
Welcome to the club.. that's the price of evasion.. There are ways to optimize it other stealth browsers to use but the trade off is they leak and are detected.
On the other side anti-bot isn't about totally blocking it's about making it cost prohibitive to get past.
1
u/usert313 4d ago
What anti bot vendor you are facing exactly? Because mostly at scale you can solve it once and get the cheaper requests at scale but it depends on the anti bot vendor how much requests it gives after having the solved challenges then you can design your optimization strategy.
1
u/bubbabu 4d ago
I’ve always wondered how those cook groups have good monitors. They seem like they use a lot of proxies OR they are hitting a specific endpoint.
1
u/Coding-Doctor-Omar 4d ago edited 4d ago
There is a neat trick that limits the bandwidth significantly (still higher than a standalone http client) and preserves all the speed. The code below gives a simple idea using InvisiblePlaywright (you can use any anti-detect browser you wish).
This code is just a proof of concept. I used to struggle from the same problem as you, and I came up with this way (I believe other people use it too, but no one told me about it before). What we're doing here is make direct, concurrent, and asynchronous http requests (from within the same browser context) to these API endpoints WHILE INHERITING THE SPOOFED TLS STACK, in contrast to
Context.request, which uses stock playwright.For very advanced anti-bot systems, you might want to initialize a background task to continuously naturally interact with the page (realistic hovering and scrolling only without clicking) while firing the requests as shown in the example. These randomized movements will grant you continuous clearances. The best library for randomized movements IMO is Shard Browser with its Motion object (a bit complex at first but is worth it once you get used to it). When using
Motion.wheel(), do not divide the scrolling into artificial steps. The Motion object handles this on its own, realistically.1
u/faultygamedev 4d ago
it depends on the scope if you're scraping. I run Camoufox browsers for my scraping and they're obviously memory heavy, but main bottleneck for me (and the one I optimize for) is residential proxy bandwidth usage. If CPU and GPU are your bottlenecks, it would help to know more about the specifics of what you're trying to scrape
1
u/Olympia_Essick 14h ago
just track how much each successful page ends up costing. scaling it sounds good until you realize each page is suddenly way more expensive