It's better to find a unique marker near the author's name instead of going through the collection of elements with like classes. For example, we can locate the title of the book using its unique id
then we locate the very next link to it (which contains the author's name) using the find_next
function. See code below.
Code:
from bs4 import BeautifulSoup as bsoup
import requests as rq
url = "http://www.amazon.com/Zealot-Times-Jesus-Nazareth-ebook/dp/B00BRUQ7ZY"
r = rq.get(url)
soup = bsoup(r.content)
title = soup.find("span", id="btAsinTitle")
author = title.find_next("a", href=True)
print title.get_text()
print author.get_text()
Result:
Zealot: The Life and Times of Jesus of Nazareth [Kindle Edition]
Reza Aslan
[Finished in 2.4s]
Hope this helps.