Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of python browser Operation

Shulou Source: shulou.com Published: 2022-06-03 17:34:45 09月29日 Update

This article mainly introduces the python browser operation example analysis, has a certain reference value, interested friends can refer to the next, I hope you read this article after a lot of gains, the following let Xiaobian take you to understand.

1. Open a session

diver = webdriver.Chrome()

2. Visit the website

diver.get("www.baidu.com")

3. Full screen, window maximization

diver.maximize_window()

4. Set the window size

diver.set_window_size(1440,900)

5. Close the browser

diver.quit()

It does three things: close the chromdiver process; close the browser; and restore some data environment.

Diver.back()

Diver.forward()

refresh: diver.refresh()

6. Get the window title

title= diver.title

Get the URL of the window

url = diver.current_url

Get the handle of the window

handle = diver.current_window_handle

examples

from selenium import webdriver#Open a session diver = webdriver.Chrome()#Fullscreen diver.maximize_window()#Visit Baidu link diver.get("https://www.baidu.com")# diver.find_elements_by_xpath("")#Baidu login diver.get("https://www.csdn.net/")#retreat diver.back()#forward diver.forward()#refresh diver.refresh()#Get title= diver.title#Get utlurl = diver.current_url#Get handle = diver.current_window_handleprint (title,url,handle)#Set window size diver.set_window_size (1440,900)#Close session diver.quit() Thank you for reading this article carefully, I hope Xiaobian shared "Python browser operation example analysis" This article is helpful to everyone, but also hope that everyone more support, pay attention to the industry information channel, more relevant knowledge waiting for you to learn!

Tags: Browser browse article example analysis handle size title maximum value interest at the same time examples data more friends environment knowledge ribbon URL Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker NVidia Microsoft MariaDB