Skip to content

Instantly share code, notes, and snippets.

@jonaslsaa
Created May 25, 2015 12:21
Show Gist options
  • Save jonaslsaa/0f6f0fd45bea7f29babf to your computer and use it in GitHub Desktop.
Save jonaslsaa/0f6f0fd45bea7f29babf to your computer and use it in GitHub Desktop.
Name Fetcher 1.2
#Python 3.4
import requests
from bs4 import BeautifulSoup
def spider(max_refresh):
file = open("names_generated.txt","w")
file.close()
file = open("names_generated.txt","a")
refresh = 1
dummy = 1
while refresh <= max_refresh:
name = ""
url = "http://www.behindthename.com/random/random.php?number=2&gender=both&surname=&all=yes" #Generator Online
source_code = requests.get(url)
# just get the code, no headers or anything
plain_text = source_code.text
# BeautifulSoup objects can be sorted through easy
soup = BeautifulSoup(plain_text)
for link in soup.findAll('a', {'class': 'plain'}):
title = link.string
try:
name += " " + title
except:
dummy = 1
try:
print(refresh)
#print(name) #Prints names to console
file.writelines(name+"\n")
except:
dummy = 1
refresh += 1
file.close()
spider(50) #How many names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment