I'm trying to get random wikipedia articles with the wikipedia API and then get all their href links which I did by:
elems = driver.find_elements_by_xpath("//a[@href]")
Then I made:
for elem in elems:
elements = []
elements.append(elem.get_attribute("href"))
In order to only get the href links from the received list with the previously executed command. I only got a single link which is:
['https://www.mediawiki.org/']
I tried to do:
for elem in elems:
elements = []
elements.extend(elem.get_attribute("href"))
Which resulted in this output:
['h', 't', 't', 'p', 's', ':', '/', '/', 'w', 'w', 'w', '.', 'm', 'e', 'd', 'i', 'a', 'w', 'i', 'k', 'i', '.', 'o', 'r', 'g', '/']
Clearly put: I want to take all href links from a random wikipedia article then put them in a single list called elements which I will later use for a for loop.
Thanks in advance.
Rest of my code if it is needed:
import wikipedia
import selenium
from selenium import webdriver
#This will get a random wikipedia article
random_article = wikipedia.random(1)
#Get the articles URL
url = wikipedia.page(random_article).url
driver = webdriver.Firefox()
driver.get(url)
elems = driver.find_elements_by_xpath("//a[@href]")
for elem in elems:
elements = []
elements.extend(elem.get_attribute("href"))
print(elements)