# !/usr/bin/python
# -*- coding: utf-8 -*-
"""
@Create : 2018/9/21
"""
from selenium import webdriver
import time
import json
if __name__ == "__main__":
pages = [{"url": 'https://error-center.aliyun.com/status/product/Ecs?spm=5176.10421674.home.5.62103af3aUyLGx',
"max_page": 25, "file": "ecs.json"}
, {"url": 'https://error-center.aliyun.com/status/product/Vpc?spm=5176.10421674.home.43.62103af3aUyLGx',
"max_page": 11, "file": "vpc.json"}]
browser = webdriver.Chrome(r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
try:
for page in pages:
url = page['url']
max_page = page['max_page']
filename = page['file']
errors = []
browser.get(url)
for cur_page in range(1, max_page + 1):
table = browser.find_element_by_class_name("table-bordered")
trs = table.find_elements_by_xpath("tbody/tr")
for i, tr in enumerate(trs):
print(tr)
print(i)
tds = tr.find_elements_by_xpath("td")
errors.append({"index": tds[0].text, "class": tds[1].text, "code": tds[2].text, "message": tds[3].text, "description": tds[4].text})
next_btn = browser.find_elements_by_class_name("ng-binding")
next_btn[-1].click()
time.sleep(5)
print cur_page
with open(filename, "w") as f:
error_str = json.dump(errors, f)
print error_str
except Exception as e:
print e