代码拉取完成,页面将自动刷新
'''
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])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。