jeudi 22 octobre 2015

How to separate/parse strings and put them into their own list? (Python Web Parsing)

from bs4 import BeautifulSoup #imports beautifulSoup package
import urllib2

url2 = 'http://ift.tt/1OK85nM'
page2 = urllib2.urlopen(url2)
soup2 = BeautifulSoup(page2.read(), "lxml")

row2 = soup2.findAll('p')
row2 = row2[18:-4] 

names2 = []
for x in row2:
    currentString2 = x.findAll('strong')
    if len(currentString2) > 0:
        currentString2 = currentString2[0]
        names2.append(currentString2.text)

This produces a list of names with first and last names. I'm trying to separate the first and last names and put all of the first names into one list and the last names into their own separate list. (Also removing the commas and spaces incidentally). What's the best way in doing so?




Aucun commentaire:

Enregistrer un commentaire