'Why does ConcurrentHashMap.computeIfAbsent() increment the counter for an already present key?

Running this example code (from Cay Horstmann)

ConcurrentHashMap<String,LongAdder> counts = new ConcurrentHashMap<>();
for (String key : "Row, row, row a boat".split("\\PL+"))
    counts.computeIfAbsent(key, k -> new LongAdder()).increment();
System.out.println(counts);

The output is

{a=1, Row=1, row=2, boat=1}

I am surprised to see row=2 because I expected computeIfAbsent() would increment only when it found the first "row" and not the second one.



Solution 1:[1]

Using vanilla Selenium generally leads to CAPTCHA / blocks due to the browser not hiding its identity as a browser automation.

I suggest trying out undetected_chromedriver - a slightly modified version of Selenium that circumvents most automated bot-detection protocols.

From the project's description:

[undetected_chromedriver is an...] optimized Selenium Chromedriver patch which does not trigger anti-bot services like Distill Network / Imperva / DataDome / Botprotect.io

I've used it quite a bit and it almost always works exactly as intended.

Here's some code to get you started:

import undetected_chromedriver.v2 as uc

# ADD CHROME OPTION -> DISABLE POPUP BLOCKING
options = uc.ChromeOptions()
options.add_argument("--disable-popup-blocking")
driver = uc.Chrome(options=options)

driver.get('https://amazon.com/')

You can visit the project's GitHub for more information. Keep in mind that you'll need to use slightly different syntax vis-a-vis regular Selenium when using certain functions.

Also, you don't need to download chromedriver.exe, as the module automatically downloads the latest version.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Robby Frank