Created
October 12, 2016 13:36
-
-
Save craigderington/ba66373b6c6b8560aba75a2c9a619895 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
#! /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