Created
July 28, 2021 17:44
-
-
Save DerekHawkins/c716b2a9153dfafa4f37b95bde4182e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 socket | |
log_file = pd.read_pickle('log.pkl') | |
log_file = log_file.ip_address.apply(lambda ip: socket.gethostbyaddr(ip)[0]) | |
# Alternative | |
from crawlerdetect import CrawlerDetect | |
crawler_detect = CrawlerDetect() | |
validate = [] | |
for crawl in log_file.user_agent: | |
data = {'valid':crawler_detect.isCrawler(crawl), | |
'bot_type':crawler_detect.getMatches()} | |
validate.append(data) | |
log_file[['valid', 'bot_type']] = pd.DataFrame(validate)[['valid', 'bot_type']] | |
log_file = log_file[log_file['valid']==True] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment