from selenium import webdriver from time import sleep bro = webdriver.Firefox() bro.get('https://www.taobao.com/') # page_text = bro.page_source() # 实现标签定位 search_input = bro.find_element_by_id('q') # 标签交互 search_input.send_keys('Iphone') # 执行一组js代码(滚动一屏的高度) bro.execute_script('window.scrollTo(0,document.body.scrollHeight)') # 点击搜索按钮 btn = bro.find_element_by_css_selector('.btn-search') btn.click() bro.get('https://wwww.baidu.com') sleep(2) # 回退 bro.back() # 前进 bro.forward() sleep(5) bro.quit()