第乙個爬蟲程式總結

2021-09-12 14:21:02 字數 1917 閱讀 2332

網路爬蟲主要分3個大的版塊:抓取分析儲存

爬蟲豆瓣讀書:

其中注意要點:xlrd/xlwt與openpyxl的讀寫效率比較

兩種包對小檔案的讀寫速度差別不大,而面對較大檔案,xlrd/xlwt速度明顯優於openpyxl,但因為xlwt無法生成xlsx是個硬傷,所以想要盡量提高效率又不影響結果時,可以考慮用xlrd讀取,用openpyxl寫入

使用方法如下:

import openpyxl

wb = openpyxl.load_workbook(r'e:\oracle筆記\表資料\exl01.xlsx')  #打excel開檔案

print(wb.sheetnames)  #獲取工作簿所有sheet名  #或者 print(wb.get_sheet_names())

sheet=wb["人員"]   #獲取工作表  #或者sheet=wb.get_sheet_by_name("人員")

print(sheet.title) #列印工作表名

sheet01=wb.active #獲取活動的工作表

print(sheet01.title)

'''操作單元格'''

print(sheet["a1"].value) #獲取單元格a1的第一行值

print(sheet["a1"].column) #獲取單元格的列值

print(sheet["a1"].row) #獲取單元格的行數

print(sheet.cell(row=2,column=1).value)  #列印第二行第一列的值

print(sheet.max_row) #列印excel的總行數

print(sheet.max_column) #列印excel的總列數

for i in range(1,sheet.max_row+1):

for j in range(1,sheet.max_column+1):

print(sheet.cell(row=i, column=j).value,end="\t")

print("")

import openpyxl

excel=open(r"e:\oracle筆記\表資料\sbb.xls","w")

exl=openpyxl.workbook("sbb.xls") #建立workbook物件

print("*"*300)

print("測試workbook部分屬性")

exl_active=exl.active #獲取當前活躍的worksheet

exl_sheet=exl.worksheets #以列表的形式返回所有的worksheet(**)

exl_rd_mode=exl.read_only #判斷是否以read_only模式開啟excel文件,

exl_enconding=exl.encoding #獲取文件的字符集編碼

exl_properties=exl.properties #獲取文件的元資料,如標題,建立者,建立日期等

exl_sheetname=exl.sheetnames #獲取工作簿中的表(列表)

print("以列表的形式返回所有的worksheet(**):",exl_sheet)

print("判斷是否以read_only模式開啟excel文件:",exl_rd_mode)

print("獲取文件的字符集編碼:",exl_enconding)

print("獲取文件的元資料:",exl_properties)

print("獲取工作簿中的表(列表):",exl_sheetname)

print("*"*300)

print("測試workbook部分方法")

excel.close()

第乙個網路爬蟲程式

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 importre importrequests 啟動兩個模組,pycharm5.0.1裡貌似不用特別啟動os模組,也可以open html requests.get aaa html.text 從目標 上捕獲源 body ...

第乙個Python爬蟲程式!

跟隨udacity的cs101課程學習,今天學完了unit 3,寫了乙個爬蟲程式 import urllib2 defget next target page start link page.find if start link 1 return none,0 start quote page.fi...

第乙個爬蟲

很多人學習python的目的就是為了學習能夠實現爬蟲的功能,這裡,我使用了scrapy框架來實現了乙個簡單的爬蟲功能,這裡我簡單的介紹一下scrapy專案的建立,和執行。1,第一步是安裝scrapy,我相信到了這一步,大多數人都已經會安裝第三方庫檔案了,這裡主要是使用命令pip install sc...