Answer the question
In order to leave comments, you need to log in
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) # Ждет загрузки браузера
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question