国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

python爬蟲教程:selenium常用API用法和瀏覽器控制

這篇具有很好參考價(jià)值的文章主要介紹了python爬蟲教程:selenium常用API用法和瀏覽器控制。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

selenium api

selenium新版本(4.8.2)很多函數(shù),包括元素定位、很多API方法均發(fā)生變化,本文記錄以selenium4.8.2為準(zhǔn)。

webdriver常用API
方法 描述
get(String url) 訪問(wèn)目標(biāo)url地址,打開(kāi)網(wǎng)頁(yè)
current_url 獲取當(dāng)前頁(yè)面url地址
title 獲取頁(yè)面標(biāo)題
page_source 獲取頁(yè)面源代碼
close() 關(guān)閉瀏覽器當(dāng)前打開(kāi)的窗口
quit() 關(guān)閉瀏覽器所有的窗口
find_element(by) 查找單個(gè)元素
find_elements(by) 查找元素列表,返回一個(gè)集合
window_handles 獲取當(dāng)前窗口句柄
from selenium import webdriver

browser = webdriver.Chrome()
browser.get('https://www.baidu.com') 

# 網(wǎng)頁(yè)標(biāo)題
print(browser.title)
# 當(dāng)前網(wǎng)址
print(browser.current_url)
# 瀏覽器名稱
print(browser.name)
# cookie
print(browser.get_cookie)
# 當(dāng)前窗口句柄
print(browser.window_handles)
# 網(wǎng)頁(yè)源碼
print(browser.page_source)
百度一下,你就知道
https://www.baidu.com/
chrome
<bound method WebDriver.get_cookie of <selenium.webdriver.chrome.webdriver.WebDriver (session="381859b7996708e36891008a494c290e")>>
['01CD0AD3FA1C37889F3BE65C61160946']
<html style="--bubble-width: 140px; --bubble-padding-left: 164px;"><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta content="always" name="referrer"><meta name="theme-color" content="#ffffff"><meta name="description" content="全球領(lǐng)先的中文搜索引擎、致力于讓網(wǎng)民更便捷地獲取信息,找到所求。百度超過(guò)千億的中文網(wǎng)頁(yè)數(shù)據(jù)庫(kù),可以瞬間找到相關(guān)的搜索結(jié)果。"><link rel="shortcut icon" href="https://www.baidu.com/favicon.ico" type="image/x-icon"><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索"><link rel="icon" sizes="any" mask="" href="https://www.baidu.com/favicon.ico"><link rel="dns-prefetch" href="http://dss0.bdstatic.com"><link rel="dns-prefetch" href="http://dss1.bdstatic.com"><link rel="dns-prefetch" href="http://ss1.bdstatic.com"><link rel="dns-prefetch" href="http://sp0.baidu.com"><link rel="dns-prefetch" href="http://sp1.baidu.com"><link rel="dns-prefetch" href="http://sp2.baidu.com"><link rel="dns-prefetch" href="http://pss.bdstatic.com"><link rel="apple-touch-icon-precomposed" href="https://psstatic.cdn.bcebos.com/video/wiseindex/aa6eef91f8b5b1a33b454c401_1660835115000.png"><title>百度一下,你就知道</title><style index="newi" type="text/css">#form .bdsug{top:39px}.bdsug{display:none;position:absolute;width:535px;background:#fff;border:1px solid #ccc!important;_overflow:hidden;box-shadow:1px 1px 3px #ededed;-webkit-box-shadow:1px 1px 3px #ededed;-moz-box-shadow:1px 1px 3px #ededed;-o-box-shadow:1px 1px 3px #ededed}.bdsug li{width:519px;color:#000;font:14px arial;line-height:25px;padding:0 8px;position:relative;cursor:default}.bdsug li.bdsug-s{background:#f0f0f0}.bdsug-store span,.bdsug-store b{color:#7A77C8}.bdsug-store-del{font-size:12px;color:#666;text-decoration:underline;position:absolute;right:8px;top:0;cursor:pointer;display:none}.bdsug-s .bdsug-store-del{display:inline-block}.bdsug-ala{display:inline-block;border-bottom:1px solid #e6e6e6}.bdsug-ala h3{line-height:14px;background:url(//www.baidu.com/img/sug_bd.png?v=09816787.png) no-repeat left center;margin:6px 0 4px;font-size:12px;font-weight:400;color:#7B7B7B;padding-left:20px}.bdsug-ala p{font-size:14px;font-weight:700;padding-left:20px}#m .bdsug .bdsug-direct p{color:#00c;font-weight:700;line-height:34px;padding:0 8px;margin-top:0;cursor:pointer;white-space:nowrap;overflow:hidden}#m .bdsug .bdsug-direct p img{width:16px;height:16px;margin:7px 6px 9px 0;vertical-align:middle}#m .bdsug .bdsug-direct p span{margin-left:8px}#form .bdsug .bdsug-direct{width:auto;padding:0;border-bottom:1px solid #f1f1f1}#form .bdsug .bdsug-direct p i{font-size:12px;line-height:100%;font-style:normal;font-weight:400;color:#fff;background-color:#2b99ff;display:inline;text-align:center;padding:1px 5px;*padding:2px 5px 0;margin-left:8px;overflow:hidden}.bdsug .bdsug-pcDirect{color:#000;font-size:14px;line-height:30px;height:30px;background-color:#f8f8f8}.bdsug .bdsug-pc-direct-tip{position:absolute;right:15px;top:8px;width:55px;height:15px;display:block;background:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/pc_direct_42d6311.png) no-repeat 0 0}.bdsug li.bdsug-pcDirect-s{background-color:#f0f0f0}.bdsug .bdsug-pcDirect-is{color:#000;font-size:14px;line-height:22px;background-color:#f5f5f5}.bdsug .bdsug-pc-direct-tip-is{position:absolute;right:15px;top:3px;width:55px;height:15px;display:block;background:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/pc_direct_42d6311.png) no-repeat 0 0}.bdsug li.bdsug-pcDirect-is-s{background-color:#f0f0f0}.bdsug .bdsug-pcDirect-s .bdsug-pc-direct-tip,.bdsug .bdsug-pcDirect-is-s .bdsug-pc-direct-tip-is{background-position:0 -15px}.bdsug .bdsug-newicon{color:#929292;opacity:.7;font-size:12px;display:inline-block;line-height:22px;letter-spacing:2px}.bdsug .bdsug-s .bdsug-newicon{opacity:1}.bdsug .bdsug-newicon i{letter-spacing:0;font-style:normal}.bdsug .bdsug-feedback-wrap{display:none}.toggle-underline{text-decoration:none}.toggle-underline:hover{text-decoration:underline}.bdpfmenu,.usermenu{border:1px solid #d1d1d1;position:absolute;width:105px;top:36px;z-index:302;box-shadow:1px 1px 5px #d1d1d1;-webkit-box-shadow:1px 1px 5px #d1d1d1;-moz-box-shadow:1px 1px 5px #d1d1d1;-o-box-shadow:1px 1px 5px #d1d1d1}.bdpfmenu{font-size:12px;background-color:#fff}.bdpfmenu a,.usermenu a{display:block;text-align:left;margin:0!important;padding:0 9px;line-height:26px;text-decoration:none}.briiconsbg{background-repeat:no-repeat;background-size:300px 18px;background-image:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/home/img/icons_0c37e9b.png);background-image:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/home/img/icons_809ae65.gif)\9}.bdpfmenu a:link,.bdpfmenu a:visited,#u .usermenu a:link,#u .usermenu a:visited{background:#fff;color:#333}.bdpfmenu a:hover,.bdpfmenu a:active,#u .usermenu a:hover,#u .usermenu a:active{background:#38f;text-decoration:none;color:#fff}.bdpfmenu{width:70px}#wrapper .bdnuarrow{width:0;height:0;font-size:0;line-height:0;display:block;position:absolute;top:-10px;left:50%;margin-left:-5px}#wrapper .bdnuarrow em,#wrapper .bdnuarrow i{width:0;height:0;font-size:0;line-height:0;display:block;position:absolute;border:5px solid transparent;border-style:dashed dashed solid}#wrapper .bdnuarrow em{border-bottom-color:#d8d8d8;top:-1px}#wrapper .bdnuarrow i{border-bottom-color:#fff;top:0}#gxszHead .prefpanelclose{cursor:pointer;width:16px;height:16px;float:right;margin-top:7px;background-position:-248px 0}#gxszHead .prefpanelclose:hover{background-position:-264px 0}.s_ipt::-webkit-input-placeholder{padding-left:3px;color:#aaa;font-size:13px}.s_ipt::-moz-placeholder{padding-left:3px;color:#aaa;font-size:13px}.s_ipt:-ms-input-placeholder{padding-left:3px;color:#aaa;font-size:13px}.s_ipt::placeholder{padding-left:3px;color:#aaa;font-size:13px}.kw-placeholder{position:absolute;top:0;left:0;color:#aaa;font-size:13px;height:40px;line-height:40px;padding-left:10px;max-width:360px;z-index:99;pointer-events:none}.kw-placeholder.kw-placehlder-high{height:40px;line-height:40px}.kw-placeholder.placeholders-hidden{visibility:hidden}#head_wrapper #form .bdsug-new{width:544px;top:35px;border-radius:0 0 10px 10px;border:2px solid #4E6EF2!important;border-top:0!important;box-shadow:none;font-family:Arial,sans-serif;z-index:1}#head_wrapper.sam_head_wrapper2 #form .bdsug-new{width:545px;z-index:1;border:1px solid #4E6EF2!important;border-top:0!important}#head_wrapper #form .bdsug-new ul{margin:7px 14px 0;padding:8px 0 7px;background:0 0;border-top:2px solid #f5f5f6}#head_wrapper #form .bdsug-new ul li{width:auto;padding-left:14px;margin-left:-14px;margin-right:-14px;color:#626675;line-height:28px;background:0 0;font-family:Arial,sans-serif}#head_wrapper #form .bdsug-new ul li .sug-search-icon,#head_wrapper #form .bdsug-new ul li .sug-history-icon{margin-right:4px;color:#222}#head_wrapper #form .bdsug-new ul li span{color:#626675}#head_wrapper #form .bdsug-new ul li b{font-weight:400;color:#222}#head_wrapper #form .bdsug-new .bdsug-store-del{font-size:13px;text-decoration:none;color:#9195A3;right:16px}#head_wrapper #form .bdsug-new .bdsug-store-del:hover{color:#315EFB;cursor:pointer}#head_wrapper #form .bdsug-new ul li:hover,#head_wrapper #form .bdsug-new ul li:hover span,#head_wrapper #form .bdsug-new ul li:hover b{cursor:pointer}.wrapper_new #form .bdsug-new .bdsug-s{background-color:#F5F5F6!important}.wrapper_new #form .sam_search .bdsug-new .bdsug-s{background-color:#F1F3FD!important}#head_wrapper #form .sam_search .bdsug-new .bdsug-s{background-color:#F1F3FD!important}#head .s-down #form .bdsug-new{top:32px}.s-skin-hasbg #head_wrapper #form .bdsug-new{border-color:#4569ff!important;border-top:0!important}.s-skin-hasbg #head_wrapper.s-down #form .bdsug-new{border-color:#4e6ef2!important;border-top:0!important}.s-skin-hasbg #head_wrapper.s-down #form.sam_search .bdsug-new{border-color:rgba(0,0,0,.05)!important;border-top:1px solid rgba(0,0,0,.05)!important;top:54px!important}#head_wrapper #form .bdsug-new .bdsug-s,#head_wrapper #form .bdsug-new .bdsug-s span,#head_wrapper #form .bdsug-new .bdsug-s b{color:#315EFB}#head_wrapper #form .bdsug-new>div span:hover,#head_wrapper #form .bdsug-new>div a:hover{color:#315EFB!important}#head_wrapper #form #kw.new-ipt-focus{border-color:#4e6ef2}#head_wrapper #form .bdsug-new ul li{}#head_wrapper #form .bdsug-new ul li .sug-hot-orange,#head_wrapper #form .bdsug-new ul li .sug-hot-grey,#head_wrapper #form .bdsug-new ul li .sug-hot-blue{display:inline-block;width:12px;height:12px;font-size:12px;line-height:12px;padding:2px;text-align:center;font-weight:500;margin-left:6px;vertical-align:text-bottom}#head_wrapper #form .bdsug-new ul li .sug-hot-orange{display:inline-block;color:#fff;background:#F60;border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-new-tag{text-align:center;margin-left:6px;box-sizing:border-box;font-size:12px;line-height:14px;padding:1px 4px;font-weight:500}#head_wrapper #form .bdsug-new ul li .sug-new-tag-grey{color:#858585;border:1px solid rgba(133,133,133,.5);border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-new-tag-blue{color:#36F;border:1px solid rgba(51,102,255,.4);border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-new-tag-orange{color:#F33;border:1px solid rgba(255,51,51,.4);border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-tag-text{display:inline-block;box-sizing:border-box;margin-left:6px;height:18px;padding:2px 4px;font-size:12px;line-height:12px;font-weight:500;text-align:center;border-radius:4px;vertical-align:middle;border-width:1px;border-style:solid}#head_wrapper #form .bdsug-new ul li .sug-tag-img{height:18px;max-width:80px;vertical-align:middle;margin-left:6px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap{display:block;height:40px;padding:7px 0;color:#222}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap:visited{color:#222}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .left-img-wrap{position:relative}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .left-img-wrap::before{content:"";width:38px;height:38px;position:absolute;top:0;right:0;left:0;bottom:0;border:1px solid rgba(0,0,0,.06);border-radius:9px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .left-img{box-sizing:border-box;float:left;width:40px;height:40px;border:1px solid rgba(0,0,0,.06);border-radius:9px;margin-right:6px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .content{float:left}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .header{margin-bottom:6px;line-height:18px;height:18px;vertical-align:middle}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .name{float:left;font-size:18px;color:#222;font-weight:500}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .tag-img{width:18px;margin-left:4px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .more{line-height:14px;width:240px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .brief,#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .info{font-size:14px;color:#222;font-weight:400}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .brief{margin-right:6px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .right-btn{float:right;margin-top:5px;margin-right:6px;width:60px;height:24px;text-align:center;font-size:14px;color:#36F;line-height:24px;background-image:linear-gradient(111deg,#e8f7ff 0,#edf0ff 100%);border-radius:12px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .right-btn:hover{background:#315efb;color:#fff}#head_wrapper #form .bdsug-new ul li:hover .direct-sug-wrap .name{color:#315EFB}#head_wrapper #form .bdsug-new ul li:hover .direct-sug-wrap .brief{color:#222}#head_wrapper.s-down #form .sam-bdsug.bdsug-new{top:52px}#head_wrapper #form .sam-bdsug.bdsug-new{width:100%;box-shadow:0 4px 4px 0 rgba(0,0,0,.1);border:1px solid rgba(0,0,0,.05)!important;border-radius:12px;top:56px}#head_wrapper #form .sam-bdsug.bdsug-new ul{border:0;padding:0 0 7px}#head_wrapper #form .sam-bdsug.bdsug-new ul li{line-height:32px}#head_wrapper #form .sam-bdsug.bdsug-new ul .bdsug-s{background-color:#F1F3FD!important}#head_wrapper #form .sam-bdsug.bdsug-new .bdsug-store-del{right:15px}.sam_search .sam_search_rec,.sam_search .sam_search_soutu{z-index:1;display:none;position:absolute;top:50%;margin-top:-12px;font-size:24px;color:#4E6EF2;height:24px;line-height:24px;width:24px;cursor:pointer;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);transition:transform .3s ease}.sam_search .sam_search_rec{right:54px}.sam_search .sam_search_soutu{right:14px}.sam_search .sam_search_rec:hover,.sam_search .sam_search_soutu:hover{color:#1D4FFF!important;transform:scale(1.08,1.08)}.sam_search .sam_search_rec_hover,.sam_search .sam_search_soutu_hover{background:#626675;border-radius:8px;height:32px;width:76px;text-align:center;line-height:32px;font-size:13px;color:#FFF;position:absolute;z-index:2;top:50px}.sam_search .sam_search_rec_hover:before,.sam_search .sam_search_soutu_hover:before{content:'';border:4px solid transparent;border-bottom:4px solid #626675;position:absolute;left:50%;top:-8px;margin-left:-4px}.sam_search .sam_search_rec_hover{right:29px}.sam_search .sam_search_soutu_hover{display:none;right:-12px}</style><style type="text/css" index="superbase">blockquote,body,button,dd,dl,dt,fieldset,form,h1,h2,h3,h4,h5,h6,hr,input,legend,li,ol,p,pre,td,textarea,th,ul{margin:0;padding:0}
html{color:#000;overflow-y:scroll;overflow:-moz-scrollbars}
body,button,input,select,textarea{font-size:12px;font-family:Arial,sans-serif}
h1,h2,h3,h4,h5,h6{font-size:100%}
em{font-style:normal}
small{font-size:12px}
ol,ul{list-style:none}
a{text-decoration:none}
a:hover{text-decoration:underline}
legend{color:#000}
fieldset,img{border:0}
button,input,select,textarea{font-size:100%}
table{border-collapse:collapse;border-spacing:0}
img{-ms-interpolation-mode:bicubic}
textarea{resize:vertical}
.left{float:left}
.right{float:right}
.overflow{overflow:hidden}
.hide{display:none}
.block{display:block}

與之前的函數(shù)名稱相比,函數(shù)前面的get都被去掉,然后函數(shù)的命名方法也從駝峰命名法變?yōu)?code>python常用的下劃線命名法。

webelement常用API

通過(guò) WebElement 實(shí)現(xiàn)與網(wǎng)站頁(yè)面上元素的交互,這些元素包含文本框、文本域、按鈕、單選框、div等。

方法 描述
click() 對(duì)元素進(jìn)行點(diǎn)擊
clear() 清空內(nèi)容(如文本框內(nèi)容)
send_keys() 寫入內(nèi)容與模擬按鍵操作
is_displayed() 元素是否可見(jiàn)(true:可見(jiàn))
is_enabled 元素是否啟用
is_selected() 元素是否已選擇
tag_name 獲取元素標(biāo)簽名
get_attritube() 獲取元素對(duì)應(yīng)的屬性值
text 獲取元素文本值(可見(jiàn)狀態(tài)下才能獲取到)
submit() 表單提交
  • 代碼示例
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

url = 'https://www.51bmj.cn/policyNotice/%E5%B9%BF%E4%B8%9C%E7%9C%81/%E5%B9%BF%E5%B7%9E%E5%B8%82/1/%E5%88%B6%E9%80%A0'

driver.get(url)

xpath = '//*[@id="__layout"]/div/div/div[2]/div[3]/div[2]/div[1]/div[1]/a'
print(xpath)

element = driver.find_element(by = By.XPATH, value=xpath)


# is_displayed 是否可見(jiàn)
print(element.is_displayed())
# is_enabled 是否啟用
print(element.is_enabled())
# is_selected 是否選擇
print(element.is_selected())
# name 元素標(biāo)簽名
print(element.tag_name)
# get_attritube 獲取元素屬性名
print(element.get_attribute('href'))
# text 獲取元素文本值
print(element.text)
//*[@id="__layout"]/div/div/div[2]/div[3]/div[2]/div[1]/div[1]/a
False
True
False
a
https://51bmj.cn/inform/3247500
控制瀏覽器

python爬蟲教程:selenium常用API用法和瀏覽器控制,python爬蟲入門教程,python,爬蟲,selenium,pandas,前端,numpy,LDA文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-752687.html

  • 代碼示例
from selenium import webdriver
import time  

browser = webdriver.Chrome()

# 設(shè)置瀏覽器全屏
browser.maximize_window()   
browser.get('https://www.baidu.com')  
time.sleep(2)

# 打開(kāi)淘寶頁(yè)面
browser.get('https://www.bilibili.com/')  
time.sleep(2)

# 后退到百度頁(yè)面
browser.back()  
time.sleep(2)

# 前進(jìn)的淘寶頁(yè)面
browser.forward() 
time.sleep(2)

# 關(guān)閉瀏覽器
browser.close()
from selenium import webdriver
import time  

driver = webdriver.Chrome()

url = 'https://bootapi.51bmj.cn/bmj-api/api/es/Policy/queryPolicyList.json?domain=undefined'

# 設(shè)置瀏覽器大?。喝?/span>
driver.maximize_window()   
driver.get('https://www.51bmj.cn/policyNotice/%E5%B9%BF%E4%B8%9C%E7%9C%81/%E5%B9%BF%E5%B7%9E%E5%B8%82/1/%E5%88%B6%E9%80%A0')  
#time.sleep(2)

# 設(shè)置分辨率 500*500
driver.set_window_size(500,500)  

# 關(guān)閉瀏覽器
#driver.close()

到了這里,關(guān)于python爬蟲教程:selenium常用API用法和瀏覽器控制的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【python爬蟲】設(shè)計(jì)自己的爬蟲 4. 封裝模擬瀏覽器 Selenium

    有些自動(dòng)化工具可以獲取瀏覽器當(dāng)前呈現(xiàn)的頁(yè)面的源代碼,可以通過(guò)這種方式來(lái)進(jìn)行爬取 一般常用的的有Selenium, playwright, pyppeteer,考慮到他們的使用有許多相同之處,因此考慮把他們封裝到一套api中 先看基類 Selenium是一個(gè)自動(dòng)化測(cè)試工具,利用它可以驅(qū)動(dòng)瀏覽器完成特定

    2024年02月03日
    瀏覽(90)
  • 【python爬蟲】10.指揮瀏覽器自動(dòng)工作(selenium)

    【python爬蟲】10.指揮瀏覽器自動(dòng)工作(selenium)

    上一關(guān),我們認(rèn)識(shí)了cookies和session。 分別學(xué)習(xí)了它們的用法,以及區(qū)別。 還做了一個(gè)項(xiàng)目:帶著小餅干登錄,然后在博客中發(fā)表評(píng)論。 除了上一關(guān)所講的登錄問(wèn)題,在爬蟲過(guò)程中,我們還可能會(huì)遇到各種各樣棘手的問(wèn)題—— 有的網(wǎng)站登錄很復(fù)雜,驗(yàn)證碼難以破解,比如大名

    2024年02月10日
    瀏覽(94)
  • python爬蟲之selenium庫(kù),瀏覽器訪問(wèn)搜索頁(yè)面并提取信息,及隱藏瀏覽器運(yùn)行

    python爬蟲之selenium庫(kù),瀏覽器訪問(wèn)搜索頁(yè)面并提取信息,及隱藏瀏覽器運(yùn)行

    如果鏈接簡(jiǎn)單,爬蟲可以通過(guò)鏈接用requests庫(kù)提取頁(yè)面信息,如爬取豆瓣top250影片信息,鏈接簡(jiǎn)單易懂。參考:爬取豆瓣top250影片信息 但如果遇到一些搜索之類的,基于js動(dòng)態(tài)加載的網(wǎng)頁(yè),以上就不適合,如爬蟲b站,搜索“爬蟲”頁(yè)面,第一頁(yè)鏈接如下,第二頁(yè)又是很長(zhǎng)沒(méi)規(guī)

    2024年01月23日
    瀏覽(228)
  • 『python爬蟲』24. selenium之無(wú)頭瀏覽器-后臺(tái)靜默運(yùn)行(保姆級(jí)圖文)

    『python爬蟲』24. selenium之無(wú)頭瀏覽器-后臺(tái)靜默運(yùn)行(保姆級(jí)圖文)

    歡迎關(guān)注 『python爬蟲』 專欄,持續(xù)更新中 歡迎關(guān)注 『python爬蟲』 專欄,持續(xù)更新中 一般性的selenium會(huì)打開(kāi)瀏覽器頁(yè)面,展示圖形化頁(yè)面給我們看,我們都應(yīng)該知道命令行式的程序肯定比這種渲染圖形化界面的程序快速高效。為了一定程度上緩解selenium慢的問(wèn)題,我們可以采

    2024年02月07日
    瀏覽(371)
  • Python小姿勢(shì) - # Python網(wǎng)絡(luò)爬蟲之如何通過(guò)selenium模擬瀏覽器登錄微博

    Python小姿勢(shì) - # Python網(wǎng)絡(luò)爬蟲之如何通過(guò)selenium模擬瀏覽器登錄微博

    Python網(wǎng)絡(luò)爬蟲之如何通過(guò)selenium模擬瀏覽器登錄微博 微博登錄接口很混亂,需要我們通過(guò)selenium來(lái)模擬瀏覽器登錄。 首先我們需要安裝selenium,通過(guò)pip安裝: ``` pip install selenium ``` 然后我們需要下載一個(gè)瀏覽器驅(qū)動(dòng),推薦使用Chrome,下載地址:http://chromedriver.storage.googleapis.c

    2024年02月03日
    瀏覽(94)
  • 已解決Python.selenium爬蟲必備設(shè)置永久禁止谷歌瀏覽器自動(dòng)升級(jí)(親測(cè)有效)

    已解決Python.selenium爬蟲必備設(shè)置永久禁止谷歌瀏覽器自動(dòng)升級(jí)(親測(cè)有效)

    問(wèn)題描述:selenium框架自動(dòng)化操作瀏覽器的時(shí)候,需要安裝瀏覽器驅(qū)動(dòng) WebDriver ,而 WebDriver 驅(qū)動(dòng)需要對(duì)應(yīng)瀏覽器的版本才運(yùn)行。但是我們常用的谷歌瀏覽器是有自動(dòng)更新的,就會(huì)經(jīng)常導(dǎo)致 WebDriver 版本和谷歌瀏覽器版本對(duì)應(yīng)不上,運(yùn)行代碼就會(huì)出現(xiàn)如下報(bào)錯(cuò)信息。 每次去下載

    2024年02月10日
    瀏覽(24)
  • python爬蟲進(jìn)階篇:Scrapy中使用Selenium模擬Firefox火狐瀏覽器爬取網(wǎng)頁(yè)信息

    接著上一篇的筆記,Scrapy爬取普通無(wú)反爬、靜態(tài)頁(yè)面的網(wǎng)頁(yè)時(shí)可以順利爬取我們要的信息。但是大部分情況下我們要的數(shù)據(jù)所在的網(wǎng)頁(yè)它是動(dòng)態(tài)加載出來(lái)的(ajax請(qǐng)求后傳回前端頁(yè)面渲染、js調(diào)用function等)。這種情況下需要使用selenium進(jìn)行模擬人工操作瀏覽器行為,實(shí)現(xiàn)自動(dòng)化

    2024年02月04日
    瀏覽(101)
  • Python爬蟲入門:使用selenium庫(kù),webdriver庫(kù)模擬瀏覽器爬蟲,模擬用戶爬蟲,爬取網(wǎng)站內(nèi)文章數(shù)據(jù),循環(huán)爬取網(wǎng)站全部數(shù)據(jù)。

    Python爬蟲入門:使用selenium庫(kù),webdriver庫(kù)模擬瀏覽器爬蟲,模擬用戶爬蟲,爬取網(wǎng)站內(nèi)文章數(shù)據(jù),循環(huán)爬取網(wǎng)站全部數(shù)據(jù)。

    *嚴(yán)正聲明:本文僅限于技術(shù)討論與分享,嚴(yán)禁用于非法途徑。 目錄 準(zhǔn)備工具: 思路: 具體操作: 調(diào)用需要的庫(kù): 啟動(dòng)瀏覽器驅(qū)動(dòng): 代碼主體: ?完整代碼(解析注釋): Python環(huán)境; 安裝selenium庫(kù); Python編輯器; 待爬取的網(wǎng)站; 安裝好的瀏覽器; 與瀏覽器版本相對(duì)應(yīng)的

    2023年04月24日
    瀏覽(103)
  • python使用selenium操作瀏覽器的教程

    python使用selenium操作瀏覽器的教程

    重復(fù)的操作令手工測(cè)試苦不堪言,于是自動(dòng)化測(cè)試出現(xiàn)了!作為web應(yīng)用里最出名的自動(dòng)化測(cè)試工具,selenium讓web應(yīng)用的測(cè)試輕松了很多。今天我們就來(lái)簡(jiǎn)單的介紹一下一些簡(jiǎn)單的selenium瀏覽器操作。接下來(lái)我們就來(lái)看看python怎么操作瀏覽器的吧! 我們使用selenium進(jìn)行自動(dòng)化測(cè)試

    2024年02月05日
    瀏覽(96)
  • 爬蟲-華為云空間備忘錄導(dǎo)出到docx-selenium控制瀏覽器行為-python數(shù)據(jù)處理

    爬蟲-華為云空間備忘錄導(dǎo)出到docx-selenium控制瀏覽器行為-python數(shù)據(jù)處理

    老的榮耀手機(jī)屬于華為云系統(tǒng),家里人換了新榮耀手機(jī)屬于榮耀云系統(tǒng)無(wú)法通過(guò)云空間將備忘錄轉(zhuǎn)移到新手機(jī),不想讓他們一個(gè)一個(gè)搞,于是整了一晚上想辦法爬取下來(lái)。從網(wǎng)頁(yè)抓取下來(lái),然后存到docx文檔中(包括文字和圖片,別的形式的內(nèi)容請(qǐng)舉一反三) 多行圖片多行文

    2024年02月19日
    瀏覽(22)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包