from selenium import webdriverfrom selenium.webdriver.common.by import by
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as ec
import time
import csv
# 1.建立瀏覽器物件
#chrome版本較高,禁用gpu加速,否則一直報錯
chrome_opt = webdriver.chromeoptions()
chrome_opt.add_argument('--disable-gpu')
path = r"chromedriver.exe"
driver = webdriver.chrome(executable_path=path,chrome_options=chrome_opt)
# 2.操作瀏覽器物件
#取出內容放入列表
def get_content():
list=
for i in range(2,30):
for s in range(1,10):
#遍歷出xpath路徑
str=f'//*[@id="form1"]/table/tbody/tr/td'
text=driver.find_element_by_xpath(str).text
return list
#對內容列表進行分組,形成列表的列表
def sort_writer(*list):
step=9
listers=[list[i:i+9] for i in range(0,len(list),step)]
with open("./zhaopin.csv","w",newline='') as f:
writer=csv.writer(f)
writer.writerows(listers)
#迴圈控制頁數
for i in range(1,400):
try:
a=get_content()
sort_writer(*a)
except exception as ide:
print("出錯了!停止")
所有通訊錄內容在 tbody》tr》td 中
#把查詢到的文字組裝成list
listconters=
conters=opq("tbody").eq(1).find("tr").children()
for td in conters:
w=td.text
#列表按個數重新分組,形成列表的列表,類似[ [a],[b],[c]..]
step=9
listconter=[listconters[i:i+step]for i in range(0,len(listconters),step)]
print(listconter)
#writerow寫一行,writerows寫列表每一項為一行,newline屬性可以避免多一行空白行
with open("./通訊錄.csv","w",newline="") as f:
writer = csv.writer (f)
writer.writerows(listconter)
python讀取手機通訊錄 python爬取通訊錄
from selenium import webdriver from selenium.webdriver.common.by import by from selenium.webdriver.support.ui import webdriverwait from selenium.webdr...
單鏈表通訊錄 通訊錄2 0
單鏈表通訊錄 通訊錄2.0 標頭檔案 ifndef address h define address h include include include define success 10000 define failure 10001 define true 10002 define false ...
python 寫的通訊錄
儲存為 book.py 執行命令 python book.py f add n name1 a address1 新增 使用者,位址 python book.py f insert n name1 a address1 新增 根據 使用者,位址 python book.py f select n n...