Created
March 25, 2013 17:09
-
-
Save bennylope/5238755 to your computer and use it in GitHub Desktop.
Queries a list of WordPress installations for the version as found in the <meta name='generator'> tag.
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
import csv | |
import requests | |
from bs4 import BeautifulSoup | |
def is_generator(tag): | |
return True if tag.attrs.get('name', '') == 'generator' else False | |
def get_version(path): | |
response = requests.get(path) | |
soup = BeautifulSoup(response.text) | |
meta_tag = soup.find(is_generator) | |
if meta_tag is None: | |
return '' | |
return meta_tag.attrs['content'] | |
def get_versions(csv_path): | |
with open(csv_path, 'r') as f: | |
reader = csv.reader(f) | |
version_list = [] | |
for row in reader: | |
version = get_version(row[0]) | |
version_list.append([row[0], version]) | |
with open('wpversions.csv', 'wb') as f: | |
writer = csv.writer(f) | |
writer.writerows(version_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment