from selenium import webdriver
from time import sleep
browser = webdriver.Firefox()
browser.get('http://fuwu.rsj.beijing.gov.cn/nwesqintegralpublic/settleperson/settlePersonTable')
browser.implicitly_wait(6)
a2 = browser.find_elements_by_xpath('//td')
print(len(a2))
f = open('beijingsettle.csv', 'at')
for i in a2[1:]:
if i.text == '查看':
f.write('\n')
continue
f.write(i.text + ',')
while 1:
browser.find_element_by_xpath('//a[@title="Go to next page"]').click()
# sleep(2)#sleep2 is important
# browser.implicitly_wait(30)
while 1:
try:
temp = []
a2 = browser.find_elements_by_xpath('//td')
print(len(a2))
for i2 in a2[1:]:
if i2.text == '查看':
temp.append('\n')
continue
temp.append(i2.text)
temp.append(',')
# f.write(i2.text + ',')
browser.find_elements_by_xpath('//td')
break
except Exception as e:
print(e)
temp.clear()
continue
for i3 in temp:
f.write(i3)