-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawler.py
51 lines (40 loc) · 1.68 KB
/
crawler.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
#!/usr/bin/env python
"""This file contains the selenium web crawler for simple web scraping
@author: Sascha Peter <[email protected]>
@version: 0.1.1
@since: 2015-11-01
@change: 0.1.1 - Put url into __init__() method and delete test method
"""
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class SeleniumCrawler(object):
"""This class provides the web crawler logic"""
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(10)
self.country_list = ["Canada", "Germany", "Iceland", "Pakistan",
"Singapore", "South Africa"]
self.driver.get("http://international.o2.co.uk/internationaltariffs/" +
"calling_abroad_from_uk")
def get_tariff_information(self, country):
"""Finds the country input element and searches for the given
country
"""
input_element = self.driver.find_element_by_id("countryName")
input_element.click()
input_element.send_keys(country)
input_element.send_keys(Keys.RETURN)
monthly_element = self.driver.find_element_by_id("paymonthly")
monthly_element.click()
def get_table_data(self):
"""Gets the table with the pricing information and prints the landline
tariff value
"""
table = self.driver.find_element_by_id("standardRatesTable")
child_elements = table.find_elements_by_xpath('.//td')
print(child_elements[1].text)
if __name__ == '__main__':
crawler = SeleniumCrawler()
for country in crawler.country_list:
crawler.get_tariff_information(country)
crawler.get_table_data()