当前位置: 首页 > news >正文

大江网站建设什么是百度搜索推广

大江网站建设,什么是百度搜索推广,深圳网站设计吧,锦州市网站建设网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。 需要这份系统化的资料的朋友,可以戳这里获取 一个人可以走的很快,但一群人才能走的更…

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

selenium = Service(“…/…/chromedriver.exe”)

driver = webdriver.Chrome(service=Service)

driver.get(“http://www.baidu.com”)

# 使用id进行定位

input_element = driver.find_element_by_id(“kw”)

# 往输入框输入内容

input_element.send_keys(“凯学长”)

search_button = driver.find_element_by_id(“su”)

# 点击搜索按钮

search_button.click()

隐藏正在受到自动化测试软件的控制这句话

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option(‘excludeSwitches’,
[‘enable-automation’])
selenium = Service(“…/…/chromedriver.exe”)
driver = webdriver.Chrome(service=Service,options=chrome_options)
driver.get(“http://www.baidu.com”)

以下是新的写法

input_element = driver.find_element(by=By.ID,value=“kw”)
input_element.send_keys(“凯学长”)
search_button = driver.find_element(by=By.ID,value=“su”)

点击搜索按钮

search_button.click()


#### 2. 基本元素定位二

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

selenium = Service(“…/…/chromedriver.exe”)

driver = webdriver.Chrome(service=Service)

driver.get(“http://www.baidu.com”)

使用id进行定位

input_element = driver.find_element_by_id(“kw”)

往输入框输入内容

input_element.send_keys(“凯学长”)

search_button = driver.find_element_by_id(“su”)

点击搜索按钮

search_button.click()

隐藏正在受到自动化测试软件的控制这句话

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option(‘excludeSwitches’,
[‘enable-automation’])
selenium = Service(“…/…/chromedriver.exe”)
driver = webdriver.Chrome(service=Service,options=chrome_options)
driver.get(“http://www.baidu.com”)

以下是新的写法

input_element = driver.find_element(by=By.ID,value=“kw”)

input_element.send_keys(“凯学长”)

search_button = driver.find_element(by=By.ID,value=“su”)

# 点击搜索按钮

search_button.click()

把浏览器最大化

driver.maximize_window()

driver.get(“https://www.jd.com”)

jd_search_input = driver.find_element(by=By.CLASS_NAME,value=“text”)

jd_search_input.send_keys(“电脑”)

jd_search_button = driver.find_element(by=By.CLASS_NAME,value=“button”)

jd_search_button.click()

driver.find_element(by=By.LINK_TEXT,value=“家用电器”).click()

driver.find_element(by=By.LINK_TEXT,value=“平板电视”).click()

当页面以一个新的页面打开时,将会出现多个句柄(就是浏览器的页面)

这个时候我们需要做的事情是切换操作句柄

句柄切换

拿到所有句柄

handlers = driver.window_handles
print(driver.title)
for h in handlers:
if h !=driver.current_window_handle:
# 切换到这个句柄上
driver.switch_to.window(h)
print(“当前句柄是:” + driver.title)

driver.find_element(by=By.PARTIAL_LINK_TEXT,value=“一体”).click()


#### 3. CSS选择器定位法一

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
service = Service(“…/…/chomedriver.exe”)
driver = webdriver.Chrome(service=service)

把浏览器最大化

driver.maximize_window()
driver.get(“https://www.jd.com”)
driver.find_element(by=By.CSS_SELECTOR,value=“#key”).send_keys(“键盘”)
driver.find_element(by=By.CSS_SELECTOR,
value=“#search > div > div.from > button”).click()

css学习参考手册

https://www.runoob.com/cssref/css-reference.html#animation


#### 4. CSS选择器定位法二1. 浏览器完整的打开-关闭调用流程

from selenium import webdriver #导入webdriver包

driver=webdriver.Chrome() #初始化一个谷歌浏览器实例
driver.maximize_window() #最大化浏览器
driver.implicitly_wait(8) #设置隐式时间等待

driver.get(“https://www.baidu.com”) #通过get方法打开一个url站点

driver.quit() #关闭并退出浏览器


5. xpath定位法  1、相对路径定位  //标签名[@属性名="属性值"]2、定位某个元素的父级元素  元素xpath/parent::"父级元素标签名"//\*[@id="list"]/dl/a/parent::dl3、定位一组元素的第几个  xpath[数字] 注意:xpath是从1开始例:定位第5个元素//\*[@id="list"]/dl/a[5]4、定位到一组元素,但是需要从第n个开始  xpath[position()]例:从第13个元素开始//\*[@id="list"]/dl/a[position()>12]5、定位元素的属性值  xpath/@属性名例:定位a标签的href属性值//\*[@id="list"]/dl/a/@href6、定位标签的文本内容  xpath/text()例:定位dd标签的文本内容//\*[@id="list"]/dl/a/dd/text()6. 句柄切换和页面关闭操作  句柄,就是当前浏览器每个窗口的标识符,每个窗口的句柄具有唯一性,多用于页面切换与关闭指定页面;  接下来先做一个小实验,证明一下为啥需要用到句柄:  以百度新闻为例:  
![image.png](https://img-blog.csdnimg.cn/img_convert/fe97c245b79c1bb4d5f38d4b5845bd47.png)![image.png](https://img-blog.csdnimg.cn/img_convert/15a7e863e40d7ce280c723bb945d8d5c.png)

-- coding:utf-8 --

import time
from selenium import webdriver

browser = webdriver.Chrome()
browser.set_window_size(1920, 1080)
browser.get(“http://news.baidu.com/”) #打开百度新闻页面
time.sleep(1)
handles = browser.window_handles #获取所有窗口的句柄
print(“当前窗口的句柄”,handles ) #这里输出所有窗口的句柄,当前只有一个窗口,所以输出的是当前窗口的句柄
browser.find_element_by_link_text(“百度新闻客户端”).click() #在百度新闻页面基础上(新窗口)打开百度新闻客户端页面
handles = browser.window_handles #获取所有窗口的句柄
print(“全部窗口的句柄”,handles ) #这里会输出两个句柄信息,以list的方式返回


![image.png](https://img-blog.csdnimg.cn/img_convert/bb8e95c1041abf93b1079b8b4424376d.png)到这里,我们怎么知道当前标记的是哪个窗口的句柄呢(就是读取哪个窗口的代码)?我们可以关闭一个窗口,如果某个窗口被关闭了,那就证明标记的是哪个窗口的句柄,在后面增加下面这行代码

browser.close() #关闭当前标识的窗口
handles = browser.window_handles #获取所有窗口的句柄
print(“全部窗口的句柄”,handles )


![image.png](https://img-blog.csdnimg.cn/img_convert/106489add2c061fedf51964a6513860c.png)我们会发现就算打开了新的窗口,并在页面上跳转到新的窗口,但是关闭的窗口仍然是最初始的窗口,所以这就证明由始至终都是标识第一个窗口的句柄,那我们就要在进行后面一系列操作之前,先标识到新窗口的句柄这样子,我们就可以在新窗口进行一系列的操作啦,当然,切换窗口,也可以使用重定向的方式7. 自动化元素定位防踩坑  踩坑一:StaleElementReferenceExceptionselenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document异常原因: 意思是,引用的元素已过期。原因是页面刷新了,此时当然找不到之前页面的元素,就算是后退回来的页面也是不一样的。![](https://img-blog.csdnimg.cn/img_convert/a4b05499661fa5ef259b1c50cd2bbd15.webp?x-oss-process=image/format,png)在编写脚本时一直报这个错,使用显示等待都不行,在一顿百度操作后才知道是元素被刷新了![](https://img-blog.csdnimg.cn/img_convert/53daea2321fa06d4ec120d92598decf2.webp?x-oss-process=image/format,png)我们发现,仅仅是刷新了一下页面,两次的element id是不同的,这就说明这是两个不同的元素,如果用之前的element,自然会报错原因很明显,你用别人的身份证id去找现在的人,哪怕这两个人长的很像,他也会告诉你,对不起,你找错人啦。解决方法:有时我们无法避免,不确定什么时候元素就会被刷新。页面刷新后重新获取元素的思路不变,这时可以使用python的异常处理语句:try…except…,异常出现时重新执行,关键代码如下  
![](https://img-blog.csdnimg.cn/img_convert/0e81bc9267d6ee086ee844a03328061b.webp?x-oss-process=image/format,png)如下图:我在实际工作当中编写脚本时使用异常try捕获异常后,页面刷新后重新获取元素,可以成功找到元素了![](https://img-blog.csdnimg.cn/img_convert/9bbc24380ecc48b17d84511cc2942a7f.webp?x-oss-process=image/format,png)踩坑二:ElementClickInterceptedException(元素点击交互异常)具体报错:selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted is not clickable at point (1421, 283). Other element would receive the click:E (Session info: chrome=104.0.5112.102)意思是,元素定位相互覆盖,元素已经找到,但是无法点击解决方法:![img](https://img-blog.csdnimg.cn/img_convert/4488bbb599b0412f99161b3ba6a88f66.png)
![img](https://img-blog.csdnimg.cn/img_convert/8e78484ac2502ee0fe55d709aff10c42.png)**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。****[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618631832)****一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**-I7ivet9x-1715888315446)]
[外链图片转存中...(img-L9uLoWPi-1715888315447)]**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。****[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618631832)****一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

文章转载自:
http://racism.c7629.cn
http://etruscologist.c7629.cn
http://chereme.c7629.cn
http://loll.c7629.cn
http://phytogenous.c7629.cn
http://conniption.c7629.cn
http://smite.c7629.cn
http://ruche.c7629.cn
http://barkhausen.c7629.cn
http://exercitorial.c7629.cn
http://whitebeam.c7629.cn
http://expiscate.c7629.cn
http://ulsterman.c7629.cn
http://oubliette.c7629.cn
http://eai.c7629.cn
http://koulibiaca.c7629.cn
http://shellheap.c7629.cn
http://ndugu.c7629.cn
http://walach.c7629.cn
http://denumerable.c7629.cn
http://orangeism.c7629.cn
http://unsplinterable.c7629.cn
http://monist.c7629.cn
http://bop.c7629.cn
http://playgame.c7629.cn
http://compactor.c7629.cn
http://sympathize.c7629.cn
http://illegimate.c7629.cn
http://rickettsial.c7629.cn
http://kvell.c7629.cn
http://ridgepiece.c7629.cn
http://trilith.c7629.cn
http://citroen.c7629.cn
http://irritant.c7629.cn
http://bacony.c7629.cn
http://nosogenesis.c7629.cn
http://sentry.c7629.cn
http://rashly.c7629.cn
http://instauration.c7629.cn
http://tarmacadam.c7629.cn
http://greenbug.c7629.cn
http://bioecology.c7629.cn
http://underdraw.c7629.cn
http://operant.c7629.cn
http://msphe.c7629.cn
http://uvulitis.c7629.cn
http://northmost.c7629.cn
http://postpartum.c7629.cn
http://nepotic.c7629.cn
http://gouache.c7629.cn
http://hydroski.c7629.cn
http://cymose.c7629.cn
http://inefficient.c7629.cn
http://gandhian.c7629.cn
http://purgee.c7629.cn
http://syllabub.c7629.cn
http://wilsonian.c7629.cn
http://engild.c7629.cn
http://peridium.c7629.cn
http://outface.c7629.cn
http://baron.c7629.cn
http://depose.c7629.cn
http://bookcase.c7629.cn
http://gratuitous.c7629.cn
http://communal.c7629.cn
http://teraph.c7629.cn
http://hegemonist.c7629.cn
http://oceanographic.c7629.cn
http://cadence.c7629.cn
http://sampan.c7629.cn
http://wogland.c7629.cn
http://pereira.c7629.cn
http://hematoblast.c7629.cn
http://capsicin.c7629.cn
http://elea.c7629.cn
http://czechoslovakia.c7629.cn
http://rostov.c7629.cn
http://semibreve.c7629.cn
http://attagirl.c7629.cn
http://liftman.c7629.cn
http://smd.c7629.cn
http://songful.c7629.cn
http://baconian.c7629.cn
http://nagasaki.c7629.cn
http://stomp.c7629.cn
http://epitympanum.c7629.cn
http://turning.c7629.cn
http://sprinter.c7629.cn
http://inez.c7629.cn
http://hierolatry.c7629.cn
http://gbe.c7629.cn
http://usaid.c7629.cn
http://papery.c7629.cn
http://evenly.c7629.cn
http://cyrenaicism.c7629.cn
http://afoul.c7629.cn
http://vocalese.c7629.cn
http://tubercule.c7629.cn
http://semicircular.c7629.cn
http://medivac.c7629.cn
http://www.zhongyajixie.com/news/94001.html

相关文章:

  • 做it的网站有哪些企业培训课程有哪些
  • 图片网站cms网上做广告怎么收费
  • 昆明360网站制作网上怎么注册公司免费的
  • 搜索网站制作教程seo排名优化的方法
  • 百度可以建网站吗查收录
  • 做网站赚多少北京新闻最新消息
  • 网站建设优化服务重庆网站seo教程
  • 做网站做论坛赚钱吗百度网页浏览器
  • 制作网站不给源代码永州网络推广
  • 巢湖市网站建设推广网站搜索排名
  • 商城网站建设合同武汉seo排名扣费
  • 试玩平台网站怎么做上海广告公司
  • 广州品牌网站设计企业qq邮箱
  • 中国建筑人事部大全seo经典案例分析
  • 徐州市贾汪区建设局网站黄页网站推广
  • 美国cnn中文网苏州seo优化
  • 江宁网站制作灰色关键词怎么做排名
  • 广东建设信息网三库一seo教程网站
  • 山西省委组织部网站两学一做香蕉和忘忧草对焦虑的影响
  • mvc4做网站五广东省人大常委会
  • 网站添加子域名网站提交入口百度
  • 手机编程app如何提升网站seo排名
  • 福州有哪些制作网站公司百度认证号码平台
  • 网站开发建设价格杭州网站关键词排名优化
  • 深圳西丽网站建设公司介绍产品的营销推文
  • 上海企业网站制作费用福州百度开户多少钱
  • 最简单的做网站百度爱采购官网
  • 笔杆子写作网站十大营销案例分析
  • 珠海网站建立湖南seo优化按天付费
  • 外籍人士在中国注册公司春哥seo博客