r/webscraping • • 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.

8 Upvotes

27 comments sorted by

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.

2

u/Fapient 4d ago

Thanks. I was hoping there was a better way, but I kinda figured as much as I couldn't see it scaling while staying affordable. Oh well.

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/Fapient 4d ago

I'm already making use of requests as an optimisation, but I can't make many without spinning up more contexts.

It eventually detects a pattern despite clean proxies and passing a normal browser, invalidating the cookies for any solved challenge. I try to browse like a human between the requests I actually want to make, but this means there is effectively a gap between captures, that can only be closed with higher scale.

1

u/usert313 4d ago

Are you using sticky proxies or rotating them on each request?

1

u/Fapient 4d ago

I'm using sticky proxies with their own profile per context. I rotate between them randomly, or when I can sense it starts to fingerprint their activity.

4

u/usert313 4d ago

Well now can't help you much without knowing the antibot vendor and your current setup.

1

u/Stock_Cabinet2267 4d ago

Probably the antibot vendor they use is collecting browser based fingerprints for each profile, so that's how they are detecting you. I am guessing though

1

u/Fapient 4d ago

Yeah, it's inevitable even though the interactions, timings, and movements are different between each profile, I suppose with AI you can easily compare and spot a bot to a genuine user.

My question was more about if it's possible to scale up more efficiently.

1

u/Stock_Cabinet2267 4d ago

Yes, theorically you could do Reverse Engineering on the communication protocol for the site that you're targeting, but it's a really time consuming task without a clear payoff, plus depending on your state it might be illegal or in the least you'll breaking their ToS.

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/Fapient 4d ago

Yeah, same. Although, they can afford to scale up even if inefficient as a single monthly subscription from a member, even for the most basic service, can probably cover a good few instances. Higher tiers can absolutely cover the expenses of good residential proxies with profit left.

There's definitely the element of good residential proxies, since whenever a proxy provider shuts down, owners and developers occasionally post on Twitter along the lines of RIP, we had a good run.

I have definitely seen some useful unguarded endpoints, but they eventually notice an increase in traffic and either shut it down or implement bot prevention measures.

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).

from invisible_playwright.async_api import InvisiblePlaywright
from playwright.async_api import Page
import asyncio

async def get(page: Page, url: str) -> dict:
    data = await page.evaluate(r'async (url) => {const res = await fetch(url); return await res.json();}', url)

    return data

async def main():
    async with InvisiblePlaywright(headless=True) as browser:
        page = await browser.new_page()
        await page.goto("https://www.website.com/")
        await page.wait_for_selector("#only-there-after-successful-load")
        product_details_api_urls = [...]
        results = await asyncio.gather(*(get(url) for url in product_details_api_urls))
        for product in results:
            print(product)

if __name__ == "__main__":
    asyncio.run(main())

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