Python——截取web網頁長圖


# -*- coding: utf8 -*-
import time
import xlrd
from selenium import webdriver

def read_excel(filename):
data = xlrd.open_workbook(filename) # 打開xls文件
sheet = data.sheets()[0] # 打開第一張表
rows = sheet.nrows # 獲取表的行數
cols = sheet.ncols # 獲取表的列數
nrows = bytes(rows)
ncols = bytes(cols)
print("共:"+nrows+"行, "+ncols+"列")
#for i in range(rows):
for i in range(3):
if i == 0:
continue
for j in range(cols - 1):
ctype = sheet.cell(i, j).ctype # 表格的數據類型
cell = sheet.cell_value(i, j)
if ctype == 2 and cell % 1 == 0.0: # ctype為2且為浮點
cell = int(cell) # 浮點轉成整型
cell = bytes(cell)
url="這里我是利用excel中的ID拼接成的URL"
print(url)
browser = webdriver.Firefox()
browser.set_window_size(1200, 900)
browser.get(url) # Load page
time.sleep(10)
js = "var q=document.documentElement.scrollTop=10000"
browser.execute_script(js)
time.sleep(10)
browser.execute_script("""
$('#main').siblings().remove();
$('#aside__wrapper').siblings().remove();
$('.ui.sticky').siblings().remove();
$('.follow-me').siblings().remove();
$('img.ui.image').siblings().remove();
""")
browser.save_screenshot("圖片保存路徑\\圖片名稱.png")
browser.close()


if __name__ == "__main__":

read_excel("excel的存放路徑\\excel名稱.xls")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM