-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebscrape2.py
120 lines (73 loc) · 2.7 KB
/
webscrape2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from bs4 import BeautifulSoup
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import pandas as pd
import re
import itertools
driver = webdriver.Chrome("C:/Python37_64/chromedriver.exe")
file_name = "C:/Users/alexdcodes/PycharmProjects//List.xlsx"
book = pd.read_excel(file_name, sheet_name = 'Good List-892')
store_list = book['S N'].tolist()
address_list = book['Address'].tolist()
enp_addresses = book['SA '].tolist()
device_list = book['Meh Number'].tolist()
total = len(store_list)
for x in range(total):
value = str(store_list[x])
if value[0] == '0':
if value[1] != '0':
store_list[x] = int(value[1:5])
elif value[2] != '0':
store_list[x] = int(value[2:5])
elif value[3] != '0':
store_list[x] = int(value[3:5])
else:
store_list[x] = int(value[4])
elif 48 <= ord(value[0]) <= 57:
store_list[x] = int(value[0:4])
if len(str(address_list[x])) < 3:
address_list[x] = enp_addresses[x]
time.sleep(4)
usernameBox = driver.find_element_by_id('login').find_element_by_id('usr_name')
passwordBox = driver.find_element_by_id('login').find_element_by_id('usr_password')
loginButton = driver.find_element_by_id('login').find_element_by_tag_name('button')
usernameBox.send_keys("nagararjan.k@eportal")
passwordBox.send_keys("Cisco#12")
loginButton.click()
time.sleep(10)
driver.switch_to.frame(driver.find_elements_by_name("leftnav")[1])
web_text = driver.page_source
time.sleep(2)
driver.find_element_by_link_text('Reporting').click()
time.sleep(7)
driver.switch_to.parent_frame()
driver.switch_to.frame('contentpage')
driver.find_element_by_link_text('Upgraded Network Performance Reporting').click()
driver.switch_to.window(driver.window_handles[1])
time.sleep(15)
ce_filter = driver.find_element_by_class_name("IvTableFilterBar").find_element_by_tag_name('span').find_element_by_tag_name('input')
ce_name = []
ip_address = []
connected_port = []
for x in range(81, 91):
ce_filter.send_keys(device_list[x])
time.sleep(1)
try:
span_list = driver.find_element_by_id('iv_table_TablePane_1-0').find_elements_by_tag_name('span')
except:
connected_port.append("ERR")
ce_name.append("ERR")
ip_address.append("ERR")
print("Issue at store" + str(store_list[x]))
ce_filter.clear()
continue
try:
connected_port.append(span_list[0].text.split()[1])
except:
connected_port.append(span_list[0].text)
ce_name.append(span_list[5].text)
if ce_name != device_list[x]:
print("Issue at store" + str(store_list[x]))
ip_address.append(span_list[9].text)
ce_filter.clear()