A
A
Alexander Mishchenko2020-04-20 19:52:14
Python
Alexander Mishchenko, 2020-04-20 19:52:14

Is it possible through Selenium+Python to open a link in a new tab in a loop?

Hello. Recently I started to learn python and selenium and now this task has become. Using selenium, I go to the admin panel of my WP site and use beautifulsoup to create a list of links of all posts. in the Loop, I go to each post and click the Publish button.

max_page = 5
for x in range(1, max_page + 1):
driver.get(BASE_URL + '?paged=' + str(x))
html = driver.page_source
soup = bs(html)

list = []
ind = -1
links = soup.find_all('a', {'class': 'row-title'})
len_anc = len(links)
print(len_anc)
for element in links:
    link = element.get('href')
    print(link)
    list.append(link)

for one_link in list:
    ind += 1
    print(one_link)
    print('Парсинг %d%% (%d/%d)' % (ind / (len_anc * max_page)*100, ind, (len_anc * max_page)))
    driver.get(one_link)
    driver.find_element_by_id("publish").click()
    time.sleep(3)  # Ждет загрузки браузера

Everything is working. But how to make it so that in the loop at each iteration a new tab opens and the page is saved and then closed? All this in order to speed up the process of updating all (2000) records.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
101-s, 2020-04-20
@101-s

Try this: Is it possible to open a new tab/window in Selenium?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question