Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thimslugga/b93a0f8a50b45f4563655e50ddba6a47 to your computer and use it in GitHub Desktop.

Select an option

Save thimslugga/b93a0f8a50b45f4563655e50ddba6a47 to your computer and use it in GitHub Desktop.
Function to parse and process output from HTTPX
def processHTTPXCrawl(programName, rawBucketPath, refinedBucketPath, inputBucketPath, presentationBucketPath):
filePath = refinedBucketPath + programName + '/' + programName + '-httpx-crawl.json'
df = pd.read_json(filePath, lines=True)
df['program'] = programName
from urllib.parse import urlparse
def _parseUrlRoot(urlvalue):
cleanurl = urlparse(urlvalue).netloc
return cleanurl
def _parseUrlBase(urlvalue):
baseurl = urlparse(urlvalue)#.netloc
baseurl = baseurl.scheme + '://' + baseurl.netloc + baseurl.path
return baseurl
df['domain'] = df['url'].apply(_parseUrlRoot)
df['baseurl'] = df['url'].apply(_parseUrlBase)
storePath = presentationBucketPath + 'urls/' + programName + '-httpx-crawl.csv'
df.to_csv(storePath, index=False, columns=['program','domain','baseurl','url','content-type','content-length','status-code'])
storePathUrl = inputBucketPath + programName + '/' + programName + '-urls-crawl.csv'
df['url'].to_csv(storePathUrl, header=False, index=False, sep='\n')
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment