首页 > Web开发 > 详细

Selenium3+webdriver学习笔记10(元素属性、页面源码)

时间:2018-12-04 21:36:04      阅读:194      评论:0      收藏:0      [点我收藏+]
#!/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()

Selenium3+webdriver学习笔记10(元素属性、页面源码)

原文:https://www.cnblogs.com/NiceTime/p/10066822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!