コード例 #1
0
ファイル: lastwords.py プロジェクト: e-dapp/Last-Words
		tempRow.append(toAppend)
		tempArray.append(tempRow)
		print 'row appended'
	return tempArray

def get_col(table_el):
	'''
	Takes in table_el, a predetermined selenuim table element, 
	returns list of text in first row.
	Makes assumption first row is column headers.
	'''

	columns = []

	for i in range(colCount):
		i += 1
		colName = table_el.find_element_by_xpath('./tbody/tr[1]/th[' + str(i) + ']').text
		if colName in columns:
			columns.append(colName + str(1))
		else:
			columns.append(colName)
		return columns

if __name__ == '__main__':
	page = Page('http://www.tdcj.state.tx.us/death_row/dr_executed_offenders.html')
	table_el = page.find_element_by_locator('class name', 'os')
	rowCount = len(table_el.find_elements_by_xpath('./tbody/tr'))
	colCount = len(table_el.find_elements_by_xpath('./tbody/tr[2]/td'))
	column_heads = get_col(table_el)
	a = scrape(table_el)
	dF = pd.DataFrame(a, columns = column_heads)