r/SeleniumPython • • Dec 19 '24

any other alternatives to selenium wire?

i’m running a scraping tool via python that extracts network response from requests that return 403 errors. i started using selenium wire and i got it to work, but the main issue is the memory increasing more and more the longer i run it.

i’ve tried everything in order for it to not increase in memory usage, but ive had no success with it.

i’m wondering if anyone has had this problem and found a solution to access these requests without memory increasing over time. or if anyone has found another solution.

i’ve tried playwright and seleniumbase, but i didn’t have success with those.

thank you.

2 Upvotes

2 comments sorted by

2

u/Floryda_Guennoc 3d ago

selenium wire keeps every captured request in memory by default, so the growth is expected, and the project was archived in early 2024 so nobody's going to fix it. if you stay on it, set request_storage_max_size in seleniumwire_options, use driver scopes so it only records the urls you need, and del driver requests after you read each response. when you search alternatives to selenium reddit mostly says playwright, but you don't have to switch, selenium 4 can read responses over cdp directly. turn on the performance log with goog:loggingPrefs, pick the requestId out of the Network responseReceived events, then driver execute_cdp_cmd('Network getResponseBody', {'requestId': rid}) gives you the body with no proxy in the middle. the 403s are a separate problem, usually the site flagging the automated browser, and if that's what keeps blocking you, scrapfly's web scraping api renders the page past the anti-bot check and returns the captured xhr calls with the result. either way restart the driver every few hundred pages, chrome itself bloats over long sessions.

1

u/Streetwise-professor Dec 21 '24

I feel like you could put in a container and play with the resources allocated /desired performance to mitigate this issue?

Also are you scraping a list of sites? If so you could break them into separate chunks and restart the apt in between possibly. All of this could be scripted as well :)