#!/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()

Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)的更多相关文章

  1. Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )

    !/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...

  2. Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...

  3. Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...

  4. Python3+Selenium3+webdriver学习笔记11(cookie处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...

  5. Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...

  6. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  7. Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  8. Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  9. Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

随机推荐

  1. POJ-3616

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10434   Accepted: 4378 Des ...

  2. hbase&nbsp;multiple&nbsp;SLF4J&amp;n…

    hbase multiple SLF4J bindings 警告 hbase shell 和命令操作中经常有个烦人的警告,说SLF4J有多个绑定: hbase(main):003:0> list ...

  3. Spring Data JPA stackoverflow

    1.禁止使用lombok 的@Data 注释 使用@Data注释后,默认会重写父类的toString()方法,hashcode()等方法,在往map里存的时候,会根据equals和hashcode方法 ...

  4. 将Gridview导出到Excel

    GridViewToExcel(EdceExcelGV, "application/ms-exce","xxxxxx表"); protected void Gr ...

  5. Git 时光穿梭鸡 撤销修改

    工作区内容修改了, 但是并未add到暂存区, 想 回退到上一个版本 在readme.txt中添加了一行: Git is a distributed version control system. Gi ...

  6. SPOJ IAPCR2F 【并查集】

    思路: 利用并查集/DFS都可以处理连通问题. PS:注意Find()查找值和pre[]值的区别. #include<bits/stdc++.h> using namespace std; ...

  7. 使用tomcat作为容器安装Jenkins

    安装前准备环境:jdk,maven,tomcat jdk 参考centos安装jdk:https://www.cnblogs.com/pipiyan/p/10491876.html maven 已有安 ...

  8. 51nod1112(xjb)

    題目鏈接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1112 題意:中文題誒- 思路:對於函數 f(x) = a + ...

  9. 洛谷 P2731 骑马修栅栏 Riding the Fences

    P2731 骑马修栅栏 Riding the Fences 题目背景 Farmer John每年有很多栅栏要修理.他总是骑着马穿过每一个栅栏并修复它破损的地方. 题目描述 John是一个与其他农民一样 ...

  10. 云服务器、虚拟主机和VPS的区别

    虚拟主机就是利用网络空间技术,把一台服务器分成许多的"虚拟"的主机,每一台网络空间都具有独立的域名和IP地址,具有完整的Internet服务器功能.网络空间之间完全独立,在外界看来 ...