Python爬虫从入门到放弃 –Selenium爬取京东商品

时间: 2024-11-10 admin IT培训

Python爬虫从入门到放弃 –Selenium爬取京东商品

Python爬虫从入门到放弃 –Selenium爬取京东商品

参考文章:

写的第一个爬虫,还有参考别人的文章,请大神多多指教

 

#我是菜鸡,只是记录下我写的第一个爬虫
#欢迎各位大佬批评
# -*- coding: UTF-8 -*-
from selenium import  webdriver
import time
import csv#搜索商品
def SearchGoods(self):browser.find_element_by_xpath('//*[@id="key"]').send_keys(self)#搜索框输入商品browser.find_element_by_xpath('//*[@id="search"]/div/div[2]/button/i').click()#点击#滑到网页底部
def SwipPage():browser.execute_script('window.scrollTo(-1,document.body.scrollHeight)')#参考文章:
#获取源码
def GetSource():html = browser.page_source time.sleep(5)#分析数据 写入文件
def WriteCsv(): li_list = browser.find_elements_by_xpath('//*[@id="J_goodsList"]/ul/li')with open(&