Selecting elements from the DOM of a page To get the book list from https://www.java67.com/2015/09/top-10-algorithm-books-every-programmer-read-learn.html , I am using the following code in the console of the firefox DevTools:
var select =  document.querySelectorAll(&quot;div.post-body.entry-content div h3 b&quot;);

for (i = 0; i &lt; select.length; ++i) {

  try {
    var title =  select[i].querySelectorAll(&quot;u&quot;)[0];
    console.log (title.innerHTML);
  }
  catch(err) {
  }

  try {
    var author =  select[i].querySelectorAll(&quot;a&quot;)[0];
    console.log (author.innerHTML);
  }
  catch(err) {
  }

}

The output is:
Introduction to Algorithms by Thomas H. Corman debugger eval code:12:13
Algorithms by Robert Sedgewick &amp;amp; Kevin Wayne debugger eval code:12:13
The Algorithm Design Manual by Steve S. Skiena debugger eval code:12:13
Algorithm for Interviews debugger eval code:12:13
5. Algorithm in Nutshell debugger eval code:5:13
6. Algorithm Design by Kleinberg &amp;amp; Tardos debugger eval code:5:13
&lt;a href=&quot;https://dev.to/javinpaul/10-best-books-to-learn-data-structure-and-algorithms-in-java-python-c-and-c-5743&quot; target=&quot;_blank&quot;&gt;7. Introduction to Algorithms: A Creative Approach&lt;/a&gt; debugger eval code:5:13
7. Introduction to Algorithms: A Creative Approach debugger eval code:12:13
8. The Design and Analysis of Algorithms debugger eval code:5:13
9. Data Structures and Algorithms. Aho, Ullman &amp;amp; Hopcroft debugger eval code:5:13
10. Python Algorithms: Mastering Basic Algorithms in the Python Language debugger eval code:5:13
undefined  

You can see from the code that the first part div.post-body.entry-content div h3 b is same. Then I am using u or a. Is there any easier way to achieve this.
Don't implicitly create global variables for (i = 0; uses a global i. Always declare variables before using them - in modern times, declare them with let or const, not var (which has too many problems, such as an unintuitive function scope rather than block scope, to be worth using nowadays)
Iterators Or, even better, rather than iterating manually, invoke the NodeList's iterator, and use for..of instead, eg:
for (const b of bs) {
  // do stuff with each &lt;b&gt; element
}

querySelector If you only want to select one element matching a selector, don't use querySelectorAll followed by [0] index lookup - use querySelector instead.
try/catch In predictable, synchronous code, there shouldn't be any need for try/catch. If you aren't sure whether an element exists, just test it first, instead of possibly throwing an error.
textContent Use textContent rather than innerHTML - textContent is faster and more appropriate when you aren't deliberately retrieving HTML markup. Also, .innerHTML gives you difficult HTML entities, as you can see with your Kleinberg &amp;amp; Tardos, instead of Kleinberg &amp; Tardos
Try something like this instead:
const bs = document.querySelectorAll(&quot;div.post-body.entry-content div h3 b&quot;);
for (const b of bs) {
  const child = b.querySelector('u, a');
  if (child) {
    console.log(child.textContent);
  }
}