#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Selenium3+webdriver学习笔记10(元素属性、页面源码)
'''
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
import re
import time,os
import random
# about:addons 火狐浏览器安装组件,访问的地址
# <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#id
keys="测试部落"
delay=3
# url="https://www.baidu.com/"
url="https://www.cnblogs.com/nicetime"
driver=webdriver.Firefox()
driver.get(url)
# <a href="http://help.baidu.com/question" target="_blank"
# onmousedown="return c({'fm':'behb','tab':'help','url':this.href,'title':this.innerHTML})">帮助</a>
#标题
title=driver.title
print(title)
#文本
text=driver.find_element_by_css_selector("div#u>a").text
print(text)
#标签名
tagname=driver.find_element_by_css_selector("div#u>a").tag_name
print(tagname)
#获取其他属性
classname=driver.find_element_by_css_selector("input#kw").get_attribute("class")
print(classname)
#获取文本框的输入内容
driver.find_element_by_id("kw").send_keys(keys)
value=driver.find_element_by_id("kw").get_attribute("value")
print(value)
#浏览器名称
print(driver.name)
time.sleep(delay)
page=driver.page_source
print(page)
result_url=[]
url_list=re.findall('href=\"(.*?)\"',page,re.S)
for url in url_list:
if 'http' in url:
result_url.append(url)
print(result_url)
driver.quit()