分离/解析特定元素的列表,并将它们放在单独的列表中。(Python)

分离/解析特定元素的列表,并将它们放在单独的列表中。(Python),python,string,list,parsing,web,Python,String,List,Parsing,Web,嘿,伙计们,我正试图解析这个列表,在这里我收集名字并把这些名字放在他们自己的列表中,然后找到姓氏并把它们放在他们自己的列表中。我也在检查他们的名字后面是否有首字母,比如“John B.Smith”,基本上跳过“B”,这样我就只在列表中加上姓氏。需要帮忙吗?我想我现在所做的就是,如果某人的名字有中间首字母,就不加姓/ 如果你自信地扔掉中间的任何东西,而且听起来你是: from bs4 import BeautifulSoup #imports beautifulSoup package impor

嘿,伙计们,我正试图解析这个列表,在这里我收集名字并把这些名字放在他们自己的列表中,然后找到姓氏并把它们放在他们自己的列表中。我也在检查他们的名字后面是否有首字母,比如“John B.Smith”,基本上跳过“B”,这样我就只在列表中加上姓氏。需要帮忙吗?我想我现在所做的就是,如果某人的名字有中间首字母,就不加姓/

如果你自信地扔掉中间的任何东西,而且听起来你是:

from bs4 import BeautifulSoup #imports beautifulSoup package
import urllib2




url2 = 'http://www.waldenu.edu/doctoral/phd-in-management/faculty'
page2 = urllib2.urlopen(url2) 
soup2 = BeautifulSoup(page2.read(), "lxml")

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

names2 = []
firstName = []
lastName = []
for x in row2:
    currentString2 = x.findAll('strong')
    if len(currentString2) > 0:
        currentString2 = currentString2[0].text
        tokens = currentString2.split(' ')
        firstName.append(tokens[0])
        for token in tokens[1:]:
           check = tokens[1]            
           if check[1] != '.': and check[1] != '\\':
               lastName.append(tokens[1])
#omitted
tokens = currentString2[0].text
assert(len(tokens) >= 2)
firstName.append(tokens[0])
lastName.append(tokens[-1])