本文整理汇总了Python中selenium.webdriver.PhantomJS.find_elements_by_class_name方法的典型用法代码示例。如果您正苦于以下问题:Python PhantomJS.find_elements_by_class_name方法的具体用法?Python PhantomJS.find_elements_by_class_name怎么用?Python PhantomJS.find_elements_by_class_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.PhantomJS
的用法示例。
在下文中一共展示了PhantomJS.find_elements_by_class_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_applications_in_page
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_elements_by_class_name [as 别名]
def get_applications_in_page(self, scroll_script):
applications = []
driver = None
try:
desired_capabilities = dict(DesiredCapabilities.PHANTOMJS)
desired_capabilities["phantomjs.page.settings.userAgent"] = useragent.get_random_agent(google_prop.user_agent_list_url)
service_args = ['--load-images=no', '--proxy=%s' % (proxy.get_random_proxy(google_prop.proxy_list_url))]
driver = PhantomJS(desired_capabilities=desired_capabilities, service_args=service_args)
# driver = Firefox(firefox_profile=self.fp, proxy=self.proxy)
if self.proxy_test:
driver.get('http://curlmyip.com/')
ip = driver.find_element_by_xpath('//body//pre').text
print('ip : [ ' + ip + ' ]')
pass
else:
driver.get(self.url)
driver.execute_script(scroll_script)
acknowledge = 0
done = False
while not done:
scroll_finished = driver.execute_script("return scraperLoadCompleted")
if scroll_finished:
if acknowledge == self.acknowledgements:
done = driver.execute_script("return scraperLoadCompleted")
pass
else:
acknowledge += 1
pass
pass
else:
acknowledge = 0
pass
time.sleep(5) # Wait before retry
pass
product_matrix = driver.find_elements_by_class_name("card")
for application in product_matrix:
extracted_application = self.extract_application_data(application)
# if extracted_application['app_price'] != -1:
applications.append(extracted_application)
#pass
pass
pass
driver.quit()
pass
except Exception as e:
if driver is not None:
driver.quit()
pass
if self.attempt < self.retries:
self.attempt += 1
time.sleep(10)
print 'retry : url [ ' + self.url + ' ] + | attempt [ ' + str(self.attempt) + ' ] | error [ ' + str(e) + ' ]'
applications = self.get_applications_in_page(scroll_script)
pass
else:
print('fail : url [ ' + self.url + ' ] | error [ ' + str(e) + ' ]')
pass
pass
return applications
pass
示例2: PhantomJS
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_elements_by_class_name [as 别名]
wd = PhantomJS()
output_cols = [
'school', 'url', 'students_per_grade', 'teachers_to_student', 'counselors_to_student', 'reading', 'math',
'science'
]
output_df = DataFrame(columns=output_cols)
output_ind = 0
for url in urls:
t1 = time()
wd.get(url)
school_name = wd.title.split(' -')[0]
print school_name,
school_info = wd.find_elements_by_class_name('school-info__item')
for s in school_info:
inner_html = sub(r'<.*?>|\n', ' ', s.get_attribute('innerHTML'))
inner_html = sub(r'\s+', ' ', inner_html).strip()
if 'grades' in inner_html.lower():
min_grade, max_grade = inner_html.split(' ')[-1].split('-')
if min_grade.lower() == 'pk':
min_grade = -1
elif min_grade.lower() == 'k':
min_grade = 0
n_grades = int(max_grade) - int(min_grade) + 1
elif 'students' in inner_html.lower():
n_students = int(sub(r'[^0-9]', '', inner_html.split(' ')[-1]))
students_per_grade = float(n_students) / float(n_grades)
staff_info = wd.find_element_by_id('TeachersStaff').find_elements_by_class_name('rating-container__score-item')