#This will not run on online IDE
import requests
import io,os
from bs4 import BeautifulSoup
import json

count = 0
i = 1

while i <= 14:
    #URL = "https://phoenixnap.com/kb/category/networking/page/"+str(i) 
    #URL = "https://phoenixnap.com/kb/category/sysadmin/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/devops-and-development/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/bare-metal-servers/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/web-servers/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/backup-and-recovery/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/security/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/virtualization/page/"+str(i)
    #URL = "https://phoenixnap.com/kb/category/databases/page/"+str(i)

    r = requests.get(URL)
    soup = BeautifulSoup(r.content, 'html5lib') # If this line causes an error, run 'pip install html5lib' 

    tutorials = soup.find_all("a", class_="post-title")

    for a_elements in tutorials:
        #print(a_elements)
        
        h3_element = a_elements.find("h3")   
        h3_text = h3_element.text

        with open("phoenixnap_database.txt", "a") as outfile:
            outfile.write(h3_text + '\n')
    i = i + 1
      
