3 Star 0 Fork 0

王继魁/python_test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
chromedriver.py 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
王继魁 提交于 2021-10-11 09:22 . crawl_homeworks
'''
import time
from selenium import webdriver # pip3 install selenium
driver = webdriver.Chrome('/Users/teacher/Documents/chromedriver') # Optional argument, if not specified will search path.
driver.get('https://www.baidu.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('wd')
search_box.send_keys('吉林师范大学')
search_box.submit()
time.sleep(10) # Let the user actually see something!
driver.quit()
'''
# import time
# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
# service = Service('/Users/teacher/Documents/chromedriver')
# service.start()
# driver = webdriver.Remote(service.service_url)
# url = 'https://list.jd.com/list.html?cat=9987,653,655'
# driver.get(url);
# html = driver.page_source
import time
from selenium import webdriver # pip3 install selenium
option = webdriver.ChromeOptions()
option.add_argument('headless') # 添加 headless 选项,提高运行效率
driver = webdriver.Chrome('/Users/teacher/Documents/chromedriver', options=option) # Optional argument, if not specified will search path.
driver.get('https://list.jd.com/list.html?cat=9987,653,655');
J_goodsList = driver.find_element_by_id('J_goodsList')
cell_phones = J_goodsList.find_elements_by_class_name('gl-item')
phones = []
for phone in cell_phones:
cell_phone = {}
cell_phone['name'] = phone.find_element_by_class_name('p-name-type-3').find_element_by_tag_name('em').text
cell_phone['price'] = phone.find_element_by_class_name('p-price').text
cell_phone['img'] = phone.find_element_by_class_name('p-img').find_element_by_tag_name('img').get_attribute('data-lazy-img')
phones.append(cell_phone)
driver.quit()
print(len(phones), phones[1])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fightvictory/python_test.git
git@gitee.com:fightvictory/python_test.git
fightvictory
python_test
python_test
master

搜索帮助