處理原理:
回圈打開頁面,回圈逐行展開客戶詳情讀取客戶資料寫入excel
參考包
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import tkinter as tk
from tkinter.filedialog import askdirectory
from lxml import etree
from openpyxl import Workbook
from openpyxl.styles import Font, colors, Alignment
from bs4 import BeautifulSoup
import pandas as pd
import time
import math
Chrom驅動加載:
option = webdriver.ChromeOptions()
# 防止列印一些無用的日志
option.add_experimental_option("excludeSwitches", ['enable-automation', 'enable-logging'])
driver = webdriver.Chrome(chrome_options=option)
回圈展開頁面資料:
for i in range(10,12): ##range(10,11)只取第10頁,取10~11頁 range設定為range(10,12)
##beginning
js="$($(document.getElementById('clubermindmessage_pager')).find('input')[0]).attr('value',"+str(i)+");$($(document.getElementById('clubermindmessage_pager')).find('input')[1]).click()"
driver.execute_script(js)
html=driver.page_source
soup=BeautifulSoup(html,"lxml")
展開客戶詳情彈窗:
js="document.getElementsByClassName('td_orderId')["+str(j-1)+"].children[0].click()"
driver.execute_script(js)
取客戶資料:
divTag = soup.find_all("div", {"id":"userDetailWinContent"})
k=0
for tag in divTag:
ulTag = tag.find_all("ul")
for tag in ulTag:
liTag = tag.find_all("li")
for tag in liTag:
spanTag = tag.find_all("span")
for tag in spanTag:
##這里寫取數邏輯,將資料寫入excel
k=k+1
關閉客戶詳情頁:
js="document.getElementsByClassName('pui-dialog-titlebar-icon pui-dialog-titlebar-close ui-corner-all')[0].click()"
driver.execute_script(js)
代碼獲取地址:https://pan.baidu.com/s/1D8Yj_Eg7RM1AWJ_85ZrdJQ
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/278086.html
標籤:python
上一篇:python多執行緒學習
下一篇:有趣python小程式系列之二