I invite the users of Mi Yodeya to check out this book which the author has essentially scraped the questions and answers on this site and is selling it.
While it might be annoying. See if you can find yourself in there. But is this legal??
This compiler, George Duckett, does that a lot. It is legal so long as he follows the CC-BY-SA license requirements, which require (1) attribution and (2) that he similarly license the product.
(2) is satisfied in the one I looked at. I found, at the very end of the book, this statement:
All questions and content contained within this book are licensed under cc-wiki with attribution required as per Stack Exchange Inc's requirements.
He also includes an email address to report copyright violations.
(1) is less clear for these Google books; he includes users' names, but I found no links to either user profiles or individual questions. Depending on how he published them, the lack of links might be ok (see TOS below). animuson♦, a Stack Exchange employee, seemed ok with the Kindle e-books, which in 2016 did link to the questions and user profiles as required. (I assume they still do.) I don't know if the lack of links in the books you found is a limitation of the Google books and, if so, who's responsible for ensuring their presence.
The editorial team for Mi Yodeya's publications is scrupulous about links and attribution. It is possible that our community's publications go beyond what is required by the license, in which case we shouldn't use our books as the yardstick to measure others by.
For reference, here is the relevant part of SE's terms of service:
In the event that You post or otherwise use Subscriber Content outside of the Network or Services, with the exception of content entirely created by You, You agree that You will follow the attribution rules of the Creative Commons Attribution Share Alike license as follows:
a. You will ensure that any such use of Subscriber Content visually displays or otherwise indicates the source of the Subscriber Content as coming from the Stack Exchange Network. This requirement is satisfied with a discreet text blurb, or some other unobtrusive but clear visual indication.
b. You will ensure that any such Internet use of Subscriber Content includes a hyperlink directly to the original question on the source site on the Network (e.g., https://stackoverflow.com/questions/12345)
c. You will ensure that any such use of Subscriber Content visually display or otherwise clearly indicate the author names for every question and answer so used.