from selenium import webdriver
import time
from selenium.webdriver.common.by import By
#将商品名称、商品价格、月销数量、商品链接保存到mysql中
from selenium.webdriver.common.keys import Keys
browser=webdriver.Chrome()
browser.get("https://uland.taobao.com/sem/tbsearch?refpid=mm_26632258_3504122_32538762&keyword=618%E8%BF%9E%E8%A1%A3%E8%A3%99&clk1=b78bc09bec900d24d1ad3cb56cfdf420&upsId=b78bc09bec900d24d1ad3cb56cfdf420")
time.sleep(3)
input_element1=browser.find_element(By.XPATH,"/html/body/div[2]/div[1]/div[2]/div[1]/div[2]/span[1]/input[1]")
input_element2=browser.find_element(By.XPATH,"/html/body/div[2]/div[1]/div[2]/div[1]/div[2]/span[1]/input[2]")
input_element1.send_keys(100)
input_element2.send_keys(800)
input_element2.send_keys(Keys.ENTER)
# button=browser.find_element(By.XPATH,"/html/body/div[2]/div[1]/div[2]/div[1]/div[2]/span[2]/input")
# button.click()
list=browser.find_elements(By.XPATH,"/html/body/div[2]/div[1]/div[2]/ul/li")
for li in list:
title=li.find_element(By.CLASS_NAME,"title-text").text
# print(title)
img=li.find_elements(By.XPATH,'/html/body/div[2]/div[1]/div[2]/ul/li[3]/a/img')
for i in img:
img_links=i.get_attribute("src")
# print(img_links)
price=li.find_element(By.CLASS_NAME,"coupon-price-afterCoupon").text
sale_num=li.find_element(By.CLASS_NAME,"sell-info").text
href=li.find_elements(By.CLASS_NAME,"pc-items-item-a")
for i in href:
goods_link=i.get_attribute("href")
# print(title,price,sale_num,goods_link)
sql="""insert into GOODS values (%s,%s,%s,%s)"""%(title,price,sale_num,goods_link)
print(sql)
from homework import conn
conn.excuteSQL(sql,None)
browser.close
报错截图
表数据: