<p>我假设您需要<code>counties</code>中的县列表。在我看来,问题在于<code>div.find_all()</code>的返回值,它最多返回一个country的数组。要填充县,请尝试以下方法:</p>
<pre><code>counties = []
for div in target_divs:
county = div.find_all('div', class_= 'table_cell_county')
for c in county:
counties.append(c.text.encode('utf-8'))
print counties # Returns: ['Autauga County', 'Baldwin County', 'Barbour County', 'Bibb County', 'Blount County', 'Bullock County', 'Butler County', 'Calhoun County', 'Chambers County', 'Chilton County', 'Choctaw County', 'Clarke County', 'Clay County', 'Coffee County', 'Colbert County', 'Conecuh County', 'Covington County', 'Crenshaw County', 'Cullman County', 'Dale County', 'Dallas County', 'Dekalb County', 'Elmore County', 'Escambia County', 'Etowah County', 'Greene County', 'Hale County', 'Henry County', 'Houston County', 'Jackson County', 'Jefferson County', 'Lauderdale County', 'Lee County', 'Limestone County', 'Lowndes County', 'Macon County', 'Madison County', 'Marengo County', 'Marion County', 'Marshall County', 'Mobile County', 'Monroe County', 'Montgomery County', 'Morgan County', 'Perry County', 'Pickens County', 'Pike County', 'Randolph County', 'Russell County', 'Saint Clair County', 'Shelby County', 'Sumter County', 'Talladega County', 'Tallapoosa County', 'Tuscaloosa County', 'Walker County', 'Wilcox County', 'Winston County']
print counties[0] # Returns: 'Autauga County'
</code></pre>