selenium

Selenium学习之==>Xpath使用方法

◇◆丶佛笑我妖孽 提交于 2021-02-11 18:29:21
一、什么是Xpath XPath是XML的路径语言,通俗一点讲就是通过元素的路径来查找到这个标签元素。 工具 Xpath的练习建议大家安装火狐浏览器后,下载插件,FireBug。由于最新版火狐不再支持FireBug等开发工具,可以通过 https://ftp.mozilla.org/pub/firefox/releases/ 下载49版本以下的火狐就可以增加Firebug等扩展了。 二、Xpath的使用方法 注:默认死格式 先写 //* 代表定位页面下所有元素 1、Xpath通过标签的属性定位 1 @代表以属性定位,后面可以接标签中任意属性 2 通过ID定位 3 //*[@id='i1'] 4 5 通过Class定位 6 //*[@class='pg-header'] 7 8 通过Name定位 9 //*[@name='username'] 10 11 通过Type定位 12 //*[@ type='button'] 2、当标签的属性重合时,Xpath提供了通过标签来进行过滤 1 获取所有input标签元素 2 //input 3 4 获取placeholder='用户名'的input标签元素 5 //input[@placeholder='用户名'] 这种方式比//*要快 6 7 当出现重复时可以使用下标定位,从1开始 8 //div[@class='inner'][2] 3

How to end a session in Selenium and start a new one?

本秂侑毒 提交于 2021-02-11 18:23:18
问题 I'm trying to quit the browser session and start a new one when I hit an exception. Normally I wouldn't do this, but in this specific case it seems to make sense. def get_info(url): browser.get(url) try: #get page data business_type_x = '//*[@id="page-desc"]/div[2]/div' business_type = browser.find_element_by_xpath(business_type_x).text print(business_type) except Exception as e: print(e) #new session browser.quit() return get_info(url) This results in this error: http.client

How to end a session in Selenium and start a new one?

萝らか妹 提交于 2021-02-11 18:23:09
问题 I'm trying to quit the browser session and start a new one when I hit an exception. Normally I wouldn't do this, but in this specific case it seems to make sense. def get_info(url): browser.get(url) try: #get page data business_type_x = '//*[@id="page-desc"]/div[2]/div' business_type = browser.find_element_by_xpath(business_type_x).text print(business_type) except Exception as e: print(e) #new session browser.quit() return get_info(url) This results in this error: http.client

Python & Selenium: Iterate through list of WebElements Error: StaleElementReferenceException

一笑奈何 提交于 2021-02-11 18:22:29
问题 Good afternoon, Somewhat new to Python and webscraping, so any help would be greatly appreciated! First: The Code from selenium import webdriver import time chrome_path = r"/Users/ENTER/Desktop/chromedriver" driver = webdriver.Chrome(chrome_path) site_url = 'https://www.home-school.com/groups/' driver.get(site_url) # get state links from sidebar and store to list area = driver.find_element_by_xpath("""/html/body/center/table/tbody/tr/td/table[3]/tbody/tr/td[2]/div""") items = area.find

https login request - selenium webdriver

自古美人都是妖i 提交于 2021-02-11 17:55:35
问题 I was trying to access a https login url to login to a page and do my actions, but unable to do the same. These are my observations. When I hit the actual url, internally its leading to another url having JSESSION ID appended to it and then loading the requested page [now actual url formed]. Steps : The actual url is like : https:/abcd.xyz.com:7443/abcd/Web/Admin when I hit the above url driver.get("https:/abcd.xyz.com:7443/abcd/Web/Admin"); and when the test is running it appended Jsession

Ask to join in Google meet Selenium

你离开我真会死。 提交于 2021-02-11 17:38:45
问题 i am working on a an api project there is a part in it which takes input from the user about Google meeting code and enter him to the google meeting the real problem is when i give it instructions to click on the button of Ask to join i have tried this : 1. driver.find_element_by_xpath( "//button[text()='Ask to join']").click() 2. driver.find_element_by_xpath( '//*[@id="yDmH0d"]/div[3]/div/div[2]/div[3]/div/span/span').click() 3. i also tried using class name every method best to my knowledge

how to use selenium to go from one url tab to another before scraping?

夙愿已清 提交于 2021-02-11 17:01:34
问题 I have created the following code in hopes to open up a new tab with a few parameters and then scrape the data table that is on the new tab. #Open Webpage url = "https://www.website.com" driver=webdriver.Chrome(executable_path=r"C:\mypathto\chromedriver.exe") driver.get(url) #Click Necessary Parameters driver.find_element_by_partial_link_text('Output').click() driver.find_element_by_xpath('//*[@id="flexOpt"]/table/tbody/tr/td[2]/input[3]').click() driver.find_element_by_xpath('//*[@id=

how to use selenium to go from one url tab to another before scraping?

二次信任 提交于 2021-02-11 17:01:02
问题 I have created the following code in hopes to open up a new tab with a few parameters and then scrape the data table that is on the new tab. #Open Webpage url = "https://www.website.com" driver=webdriver.Chrome(executable_path=r"C:\mypathto\chromedriver.exe") driver.get(url) #Click Necessary Parameters driver.find_element_by_partial_link_text('Output').click() driver.find_element_by_xpath('//*[@id="flexOpt"]/table/tbody/tr/td[2]/input[3]').click() driver.find_element_by_xpath('//*[@id=

how to use selenium to go from one url tab to another before scraping?

时光毁灭记忆、已成空白 提交于 2021-02-11 17:00:44
问题 I have created the following code in hopes to open up a new tab with a few parameters and then scrape the data table that is on the new tab. #Open Webpage url = "https://www.website.com" driver=webdriver.Chrome(executable_path=r"C:\mypathto\chromedriver.exe") driver.get(url) #Click Necessary Parameters driver.find_element_by_partial_link_text('Output').click() driver.find_element_by_xpath('//*[@id="flexOpt"]/table/tbody/tr/td[2]/input[3]').click() driver.find_element_by_xpath('//*[@id=

webscraping using python and selenium and tried to use multiprocessing but code not working. without it code works fine

泄露秘密 提交于 2021-02-11 16:56:58
问题 Am doing web scraping with python & selenium. I used to scrape data for one location & year at a time, by creating 1800 .py files (600 places * 3 years = 1800) and batch opening 10 at a time and waiting for it to complete. which is time-consuming so I decided to use multiprocessing. I made my code to read places data from a text file and iterate with it. the text file looks like this Aandimadam Aathur_Dindugal Aathur_Salem East Abiramam Acchirapakkam Adayar Adhiramapattinam Alandur