京东商品爬取
仅供学习
一.使用selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys #键盘按键操作from selenium.webdriver.support import expected_conditions as EC
import time
def get_goods(driver):
try:
goods=driver.find_elements_by_class_name('gl-item')
for good in goods:
detail_url=good.find_element_by_tag_name('a').get_attribute('href')
p_name=good.find_element_by_css_selector('.p-name em').text.replace('\n','')
price=good.find_element_by_css_selector('.p-price i').text
p_commit=good.find_element_by_css_selector('.p-commit a').text
msg = '''
商品 : %s
链接 : %s
价钱 :%s
评论 :%s
''' % (p_name,detail_url,price,p_comm