I'm trying to access hyperlink texts that will always be stored as the last hyperlink tag nested in 100 div tags on a certain website. In the below example, "00A17" would be what I'm trying to extract from a single tag.
HTML Code:
<div class="headlineText">
<a class="mrnum" title="Full MathSciNet Item" href="/mathscinet/search/publdoc.html?arg3=&co4=AND&co5=AND&co6=AND&co7=AND&dr=all&extend=1&l=100&pg4=AUCN&pg5=TI&pg6=PC&pg7=ALLF&pg8=ET&review_format=html&s4=&s5=&s6=&s7=%22Featured%20Review%22&s8=Journals&sort=Newest&vfpref=html&yearRangeFirst=&yearRangeSecond=&yrop=eq&r=9&mx-pid=2650657"><strong>MR2650657</strong></a>
<a class="item_status" href="/mathscinet/help/fullitem_help_full.html#indexed"><span>Indexed</span></a>
<a href="/mathscinet/search/author.html?mrauthid=115370">Logan, J. David</a> <span class="title"><span class="searchHighlight">Featured review</span>: <span class="it">Introduction to the foundations of applied mathematics</span> [<a href="/mathscinet/search/publdoc.html?pg1=MR&s1=2526777&loc=fromrevtext">MR2526777</a>].</span>
<a href="/mathscinet/search/journaldoc.html?id=5174"> <em>SIAM Rev.</em></a> <a href="/mathscinet/search/publications.html?pg1=ISSI&s1=281478"> 52 </a>
<a href="/mathscinet/search/publications.html?pg1=ISSI&s1=281478"> (2010), </a>
<a href="/mathscinet/search/publications.html?pg1=ISSI&s1=281478"> no. 1,</a> 173–178.
<a href="/mathscinet/search/mscdoc.html?code=00A17">00A17</a>
</div>
The code I wrote to attempt this is basically a mess
Python Code for remote access:
headlineTexts = []
mscLinks = []
for x in range(2,102):
headlineTexts.extend(driver.find_elements_by_xpath("//*[@id='content']/form/div[3]/div[2]/div/div/div[%d]/div[2]"%x))
mscLinks.extend(headlineTexts[x-2].find_elements_by_tag_name("a")[last()])
Essentially, there are 100 "headlineText" div tags (indexed from 2 to 101), and I need to get the aforementioned hyperlink text out of each one (hence the iteration). I'm basically creating a list of headlineText elements and then for each headlineText element I'm attempting to extract the last subelement with the tag name "a". Unfortunately, when I attempt to run this I get a
TypeError: 'WebElement' object is not iterable
which is strange to me because I'm only using the plural find_elements() and that should generate an iterable list. Am I perhaps using last() incorrectly?