Skip to content

Instantly share code, notes, and snippets.

@craigderington
Created October 12, 2016 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigderington/ba66373b6c6b8560aba75a2c9a619895 to your computer and use it in GitHub Desktop.
Save craigderington/ba66373b6c6b8560aba75a2c9a619895 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
import os
import re
import requests
from bs4 import BeautifulSoup
url = 'http://random-name-generator.info'
hdr = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36',
}
r = requests.get(url, headers=hdr)
soup = BeautifulSoup(r.text, 'lxml')
name_list = soup.find('ol', class_='nameList')
names = name_list.find_all('li')
for idx, name in enumerate(names):
if idx == 0:
person = name.text.split(' ')
first_name = person[0]
last_name = person[1]
print(first_name + ' ' + last_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment