Python+Selenium自動化篇-5-獲取頁面信息

1.獲取頁面title

  • title:獲取當前頁面的標題顯示的字段
from selenium import webdriver
import time  browser = webdriver.Chrome()
browser.get('https://www.baidu.com')  #打印網頁標題
print(browser.title)
#輸出內容:百度一下,你就知道

2.獲取頁面URL

  • current_url:獲取當前頁面的URL
from selenium import webdriver
import time  browser = webdriver.Chrome()
browser.get('https://www.baidu.com')  #打印網頁標題
print(browser.current_url)
#輸出內容:https://www.baidu.com/

3.獲取瀏覽器版本號

  • capabilities['version']):打印瀏覽器version的值
from selenium import webdriver
import time  browser = webdriver.Chrome()
browser.get('https://www.baidu.com')  #打印網頁標題
print(browser.capabilities['version'])
#輸出內容:67.0.3396.87

4.獲取元素尺寸

  • size:返回元素的尺寸
from selenium import webdriver
import time  browser = webdriver.Chrome()
browser.get('https://www.baidu.com')  #定位輸入框
input_box = browser.find_element_by_id('kw')
#打印輸入框尺寸
print(input_box.size)
#輸出內容:{'height': 22, 'width': 500}

5.獲取元素的文本

  • text:返回元素的文本信息
from selenium import webdriver
import time  browser = webdriver.Chrome()
browser.get('https://www.baidu.com')  #定位備案元素
recordcode = browser.find_element_by_id('jgwab')
#打印備案元素信息
print(recordcode.text)
#輸出內容:京公網安備11000002000001號

6.獲得屬性值

  • get_attribute('')方法
  • get_attribute('href'):獲取href屬性值
  • get_attribute('id'):獲取id屬性值
# coding=utf-8
import time
from selenium import webdriverdriver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(6)
driver.get("https://www.baidu.com")
time.sleep(1)for link in driver.find_elements_by_xpath("//*[@href]"):print (link.get_attribute('href'))
driver.quit()

轉載于:https://www.cnblogs.com/jasontang369/p/9212026.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389405.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389405.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389405.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

火種 ctf_分析我的火種數據

火種 ctfOriginally published at https://www.linkedin.com on March 27, 2020 (data up to date as of March 20, 2020).最初于 2020年3月27日 在 https://www.linkedin.com 上 發布 (數據截至2020年3月20日)。 Day 3 of social distancing.社會疏離的第三天。 As I sit on…

莫煩Matplotlib可視化第五章動畫代碼學習

5.1 Animation 動畫 import numpy as np import matplotlib.pyplot as plt from matplotlib import animationfig,ax plt.subplots()x np.arange(0,2*np.pi,0.01) line, ax.plot(x,np.sin(x))def animate(i):line.set_ydata(np.sin(xi/10))return line,def init():line.set…

data studio_面向營銷人員的Data Studio —報表指南

data studioIn this guide, we describe both the theoretical and practical sides of reporting with Google Data Studio. You can use this guide as a comprehensive cheat sheet in your everyday marketing.在本指南中,我們描述了使用Google Data Studio進行…

人流量統計系統介紹_統計介紹

人流量統計系統介紹Its very important to know about statistics . May you be a from a finance background, may you be data scientist or a data analyst, life is all about mathematics. As per the wiki definition “Statistics is the discipline that concerns the …

pyhive 連接 Hive 時錯誤

一、User: xx is not allowed to impersonate xxx 解決辦法&#xff1a;修改 core-site.xml 文件&#xff0c;加入下面的內容后重啟 hadoop。 <property><name>hadoop.proxyuser.xx.hosts</name><value>*</value> </property><property…

樂高ev3 讀取外部數據_數據就是新樂高

樂高ev3 讀取外部數據When I was a kid, I used to love playing with Lego. My brother and I built almost all kinds of stuff with Lego — animals, cars, houses, and even spaceships. As time went on, our creations became more ambitious and realistic. There were…

圖像灰度化與二值化

圖像灰度化 什么是圖像灰度化&#xff1f; 圖像灰度化并不是將單純的圖像變成灰色&#xff0c;而是將圖片的BGR各通道以某種規律綜合起來&#xff0c;使圖片顯示位灰色。 規律如下&#xff1a; 手動實現灰度化 首先我們采用手動灰度化的方式&#xff1a; 其思想就是&#…

分析citibike數據eda

數據科學 (Data Science) CitiBike is New York City’s famous bike rental company and the largest in the USA. CitiBike launched in May 2013 and has become an essential part of the transportation network. They make commute fun, efficient, and affordable — no…

jvm感知docker容器參數

docker中的jvm檢測到的是宿主機的內存信息&#xff0c;它無法感知容器的資源上限&#xff0c;這樣可能會導致意外的情況。 -m參數用于限制容器使用內存的大小&#xff0c;超過大小時會被OOMKilled。 -Xmx: 默認為物理內存的1/4。 4核CPU16G內存的宿主機 java 7 docker run -m …

Flask之flask-script 指定端口

簡介 Flask-Scropt插件為在Flask里編寫額外的腳本提供了支持。這包括運行一個開發服務器&#xff0c;一個定制的Python命令行&#xff0c;用于執行初始化數據庫、定時任務和其他屬于web應用之外的命令行任務的腳本。 安裝 用命令pip和easy_install安裝&#xff1a; pip install…

上采樣(放大圖像)和下采樣(縮小圖像)(最鄰近插值和雙線性插值的理解和實現)

上采樣和下采樣 什么是上采樣和下采樣&#xff1f; ? 縮小圖像&#xff08;或稱為下采樣&#xff08;subsampled&#xff09;或降采樣&#xff08;downsampled&#xff09;&#xff09;的主要目的有 兩個&#xff1a;1、使得圖像符合顯示區域的大小&#xff1b;2、生成對應圖…

r語言繪制雷達圖_用r繪制雷達蜘蛛圖

r語言繪制雷達圖I’ve tried several different types of NBA analytical articles within my readership who are a group of true fans of basketball. I found that the most popular articles are not those with state-of-the-art machine learning technologies, but tho…

java 分裂數字_分裂的補充:超越數字,打印物理可視化

java 分裂數字As noted in my earlier Nightingale writings, color harmony is the process of choosing colors on a Color Wheel that work well together in the composition of an image. Today, I will step further into color theory by discussing the Split Compleme…

Java 集合 之 Vector

http://www.verejava.com/?id17159974203844 import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Vector;public class Test {/*** param args the command line arguments*/public static void main(String[] args) {//打印…

前端電子書單大分享~~~

前言 純福利&#xff0c; 如果你不想買很多書&#xff0c;只想省錢看電子書&#xff1b; 如果你找不到很多想看書籍的電子書版本&#xff1b; 那么&#xff0c;請保存或者下載到自己的電腦或者手機或者網盤吧。 不要太著急&#xff0c;連接在最后呢 前端 前端框架 node html-cs…

結構化數據建模——titanic數據集的模型建立和訓練(Pytorch版)

本文參考《20天吃透Pytorch》來實現titanic數據集的模型建立和訓練 在書中理論的同時加入自己的理解。 一&#xff0c;準備數據 數據加載 titanic數據集的目標是根據乘客信息預測他們在Titanic號撞擊冰山沉沒后能否生存。 結構化數據一般會使用Pandas中的DataFrame進行預處理…

比賽,幸福度_幸福與生活滿意度

比賽,幸福度What is the purpose of life? Is that to be happy? Why people go through all the pain and hardship? Is it to achieve happiness in some way?人生的目的是什么&#xff1f; 那是幸福嗎&#xff1f; 人們為什么要經歷所有的痛苦和磨難&#xff1f; 是通過…

帶有postgres和jupyter筆記本的Titanic數據集

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.PostgreSQL是一個功能強大的開源對象關系數據庫系統&am…

Django學習--數據庫同步操作技巧

同步數據庫&#xff1a;使用上述兩條命令同步數據庫1.認識migrations目錄&#xff1a;migrations目錄作用&#xff1a;用來存放通過makemigrations命令生成的數據庫腳本&#xff0c;里面的生成的腳本不要輕易修改。要正常的使用數據庫同步的功能&#xff0c;app目錄下必須要有m…

《20天吃透Pytorch》Pytorch自動微分機制學習

自動微分機制 Pytorch一般通過反向傳播 backward 方法 實現這種求梯度計算。該方法求得的梯度將存在對應自變量張量的grad屬性下。 除此之外&#xff0c;也能夠調用torch.autograd.grad 函數來實現求梯度計算。 這就是Pytorch的自動微分機制。 一&#xff0c;利用backward方…