Created
July 29, 2022 14:34
-
-
Save incogbyte/6ad55042c2a64a64d50934000852ca6f to your computer and use it in GitHub Desktop.
download plugins for wordpress
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