Skip to content

Instantly share code, notes, and snippets.

@linlincheng
Created August 21, 2016 20:26
Show Gist options
  • Save linlincheng/ca638c95a3acbf96a21a08d0dad02cf3 to your computer and use it in GitHub Desktop.
Save linlincheng/ca638c95a3acbf96a21a08d0dad02cf3 to your computer and use it in GitHub Desktop.
#Step 4. Create the item info file:
import itertools
merged_item_list = list(itertools.chain(*item_url_list))
driver = webdriver.Chrome()
final_item_result_list = []
for url in merged_item_list:
try:
driver.get(url)
except:
print driver.current_url
pass
try:
driver.find_element_by_class('christies-icon_close closeiframe').click()
except:
pass
try:
item_detail = {}
item_detail['url'] = url
item_detail['ID'] = driver.find_element_by_id('main_center_0_lnkSaleNumber').text.encode('ascii', 'ignore').strip()
item_detail['Primary_Title'] = driver.find_element_by_id('main_center_0_lblLotPrimaryTitle').text.encode('ascii', 'ignore').strip()
item_detail['Secondary_title'] = driver.find_element_by_id('main_center_0_lblLotSecondaryTitle').text.encode('ascii', 'ignore').strip()
item_detail['Price'] = driver.find_element_by_id('main_center_0_lblPriceRealizedPrimary').text.encode('ascii', 'ignore').strip()
item_detail['Description'] = driver.find_element_by_id('main_center_0_lblLotDescription').text.encode('ascii', 'ignore').strip()
final_item_result_list.append(item_detail)
print item_detail['Primary_title']
except Exception as e:
print e
pass
driver.close()
##save new_list to a data framed file:
keys = final_item_result_list[0].keys()
with open("final_item_list.csv", "w") as f:
dict_writer = DictWriter(f, keys, delimiter=",")
dict_writer.writeheader()
for value in final_item_result_list:
dict_writer.writerow(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment