current position:Home>Python combat series - search Liu Haocun, how easy to search how to search

Python combat series - search Liu Haocun, how easy to search how to search

2022-11-08 08:08:31Python-Basketball

If you use python to search for stars, such as Liu Haocun
insert image description here

1. First develop Chrome browser
2. Enter the address of www.baidu.com on the browser
3. Then enter "Liu Haocun" and other names, click search

Simple one-person search is very simple, but we want to search 100 people's names at once, and manual labor is too inefficient. At this time, Python can solve our worries.

from selenium import webdriverimport timefrom selenium.webdriver.common.by import Bybrowser = webdriver.Chrome()browser.get("https://www.baidu.com/")browser.find_element(By.XPATH, value='//*[@id="kw"]').send_keys('Liu Haocun')browser.find_element(By.XPATH, value='//*[@id="su"]').click()time.sleep(3) # Generally, you need to set the sleep time, because it takes time to load the webpage after clicking the jumpdata = browser.page_sourceprint(data)

The above program simulates the previous 3 steps.
insert image description here

copyright notice
author[Python-Basketball],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/312/202211080751490366.html

Random recommended