Im trying to scrap urls from a website and then output them in a csv. The code is working, but not going to the next page as the website is paginated. While the counter is increasing and changing the url, the page that is loading is page 1.
How do I resolve this?
import csv
from selenium import webdriver
MAX_PAGE_NUM =3
MAX_PAGE_DIG=1
driver = webdriver.Firefox()
for i in range(1, MAX_PAGE_NUM + 1):
page_num = (MAX_PAGE_DIG - len (str(i))) *'0' + str(i)
driver.get("https://www.example.com/user/learn/freehelp/dynTest/1/Landing/1/page"+page_num)
find_href = driver.find_elements_by_xpath('//div[@class="col-md-12"]/a')
num_page_items= len(find_href)
with open('links1.csv', 'a') as f:
for i in range(num_page_items):
for my_href in find_href:
f.write(my_href.get_attribute("href") +'\n')
driver.close()