随笔分类 -  python+selenium

技术有限,努力成长
摘要:1、页面上下滚动,滚动的位置根据Y坐标 js = f"window.scrollTo(0,{val});" driver.execute_script(js) 2、页面上下滚动,滚动到目标元素处 selector = case.get('selector') driver = mainhandler 阅读全文
posted @ 2021-08-04 15:58 狂飙的老蜗牛 阅读(416) 评论(0) 推荐(0)
摘要:1、contains(a, b) 如果a中含有字符串b,则返回true,否则返回false driver.find_element_by_xpath("//div[contains(@id, 'btn-attention')]") 2、starts-with(a, b) 如果a是以字符串b开头,返回 阅读全文
posted @ 2021-06-21 10:26 狂飙的老蜗牛 阅读(569) 评论(0) 推荐(0)
摘要:# coding:utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Firefox() driver.get 阅读全文
posted @ 2021-02-24 14:51 狂飙的老蜗牛 阅读(463) 评论(0) 推荐(0)
摘要:1、通过父节点定位子节点 # 1.串联寻找 print driver.find_element_by_id('B').find_element_by_tag_name('div').text # 2.xpath父子关系寻找 print driver.find_element_by_xpath("// 阅读全文
posted @ 2021-02-24 14:37 狂飙的老蜗牛 阅读(3920) 评论(0) 推荐(0)
摘要:1、xpath匹配到多个元素如何选择指定的元素定位 (1)xpath匹配到多个元素,选择指定的元素,通过末尾的数字选择具体的元素 (//span[@id=‘example’])[2] (2)xpath定位到统计标签的最后一个 //span[@id='example']/a[last()] (3)xp 阅读全文
posted @ 2021-01-27 13:15 狂飙的老蜗牛 阅读(4896) 评论(0) 推荐(0)
摘要:1、如果是通过request请求的话,则在verify参数设置为False res=requests.get(url,verify=False) 2、如果是通过selenium的话,则添加参数 --ignore-certificate-errors options.add_argument('--i 阅读全文
posted @ 2020-12-30 21:23 狂飙的老蜗牛 阅读(744) 评论(0) 推荐(0)
摘要:1/如果已知接下来的操作会增加新的窗口,可以直接使用如下方法 def switch_to_cur_win(driver): try: all_win = driver.window_handle all_win_num = len(all_win) driver.switch_to.window(a 阅读全文
posted @ 2020-12-28 17:15 狂飙的老蜗牛 阅读(313) 评论(0) 推荐(0)