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")

转载于:https://www.cnblogs.com/wanglei-xiaoshitou1/p/9429074.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值