-1
try:
    links = driver.find_elements_by_xpath('//div[@class="s-item__wrapper clearfix"]//a[@class="s-item__link"]')
    for link in links:
        print(link.get_attribute('href'))

I want to save all links file in txt file

1 Answers1

2
with open('links.txt', 'w') as file:
    try:
        links = driver.find_elements_by_xpath('//div[@class="s-item__wrapper clearfix"]//a[@class="s-item__link"]')
        file.write('\n'.join(links))

Use open() to open files for read or write. More info here.

Rocket Nikita
  • 470
  • 2
  • 7
  • 20