Created
September 19, 2022 13:43
-
-
Save rodnt/7aeac286455ff0c8cda9fe153bb34c6c to your computer and use it in GitHub Desktop.
Download all plugins from wordpress and save it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shutil import ExecError | |
import requests | |
from bs4 import BeautifulSoup | |
import os | |
import wget | |
from concurrent.futures import ThreadPoolExecutor | |
import zipfile | |
def wordpress_plugin(): | |
urls = [] | |
for i in range(20, 30): | |
url = "https://wordpress.org/plugins/browse/popular/page/"+str(i) | |
cookies = {"cookies": ""} | |
print(':: Get plugins on Page - '+ url) | |
result = requests.get(url, cookies=cookies) | |
soup = BeautifulSoup(result.content, 'html.parser') | |
results = soup.findAll("h3", {"class": "entry-title"}) | |
for strings in results: | |
urls.append(strings.find('a')['href']) | |
return urls | |
def downloader(urls_to_download): | |
req = requests.get(urls_to_download) | |
filename = urls_to_download.split('/')[-1] | |
zipfilepath = 'uploads/zipwordpressplugins/'+filename | |
print("\nDownloading File in - ", str(zipfilepath), "\n") | |
print(urls_to_download, '\n') | |
unzipfilepath = 'uploads/unzipwordpressplugins/' | |
with open(zipfilepath,'wb') as output_file: | |
output_file.write(req.content) | |
print('Downloading Completed') | |
with zipfile.ZipFile(zipfilepath, 'r') as zip_ref: | |
print("Unzipped - ", str(unzipfilepath), str(filename)) | |
zip_ref.extractall(unzipfilepath) | |
def download(): | |
urls_to_download = [] | |
urls = wordpress_plugin() | |
print(':: Grep urls for donwload :: ') | |
for pluginurl in urls: | |
result = requests.get(pluginurl) | |
soup = BeautifulSoup(result.content, 'html.parser') | |
results = soup.find_all("a", {"class": "plugin-download button download-button button-large"}) | |
for result in results: | |
urls_to_download.append(result.get('href')) | |
with ThreadPoolExecutor(max_workers=10) as executor: | |
executor.map(downloader, urls_to_download) | |
download() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment