There are two links format: (with title in a[1] or a[2]
I want it clicks all links in the websites in every page, but using the following codes, it just clicking the first one again and again.
The first link in the website is always [2], with the rest are a[1], I don't know how to click all links then if only use a[1], then 'WebDriverException: unknown error: unsupported protocol (Session info: chrome=88.0.4324.104)'.
<div class="company-left-title">
<a href="javascript:Go('/qy-l-0-4-3595-3595-1.html');">
</a>
<a href="http://15256160037.58food.com/" target="_blank">亳州市九熹堂药业有限公司</a>
</div>
OR
<div class="company-left-title">
<a href="http://hubeianran.58food.com/" target="_blank">湖北安然保健品有限公司</a>
</div>
I used:
driver.get('http://www.58food.com/qy-l-0-3595.html')
while True:
try:
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath('//*[@class="company-left-title"]/a[2]')]
except:
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath('//*[@class="company-left-title"]/a[1]')]
for link in links:
driver.get(link)
driver.back()