第二十八課

一、代碼一

import csv
fileName = "test.csv"
with open(fileName, "r", encoding="utf-8") as f:
    text = csv.reader(f)
    for line in text:
        for i in line:
            print(i)
with open(fileName, "r", encoding="utf-8") as f:
    for line in f:
        for i in line.split(","):
            print(i.strip())

二、代碼二

import xlrd
data = xlrd.open_workbook("test.xlsx")
table = data.sheets()[0]
rows = table.nrows
cols = table.ncols
print(cols)
for i in range(rows):
    print(table.row_values(i))

print("##"*10)
for j in range(cols):
    print(table.col_values(j))

print("###"*10)
for row in range(rows):
    for col in range(cols):
        cell = table.cell_value(row, col)
        print(cell)

三、代碼三

import xlwt

workbook = xlwt.Workbook()
sheet1 = workbook.add_sheet("test1", cell_overwrite_ok=True)
sheet1.write(0,0,"hello1")
sheet1.write(0,1,"hello2")
sheet1.write(0,2,"hello3")
sheet1.write(1,0,"word1")
sheet1.write(1,1,"word2")
sheet1.write(1,2,"word3")
sheet1.write(1,3,"word4")

workbook.save("testwrite.xls")
print("create ok")

四、代碼四

import pdfkit

# pdfkit.from_url("https://www.jd.com", 'jdindex.pdf')
# pdfkit.from_file("test.html", 'test.pdf')
pdfkit.from_string('sasdlfjalsdfjlsda;jfl;sdajfl;asdjflasdjfl;sdajfla;sdjfl;asdjf', 'str.pdf')

五、代碼五

import codecs
import os
import sys

import pdfkit
import requests

base_url = 'http://www.apelearn.com/study_v2/'
if not os.path.exists("aming"):
    os.mkdir("aming")

os.chdir("aming")
s = requests.session()

for i in range(1, 27):
    url = base_url + 'chapter' + str(i) + '.html'
    print(url)
    file = str(i) + '.pdf'
    print(file)
    config = pdfkit.configuration(wkhtmltopdf=r"D:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
    try:
        pdfkit.from_url(url, file)
    except:
        continue

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章