爬虫:
import requests
import bs4
url="http://jyt.ln.gov.cn/"
resp=requests.get(url)
# print(resp.content)
# 树状结构的对象(dom )
soup=bs4.BeautifulSoup(resp.content,'html.parser')
a=soup.select('ul.gov_list2>li>a')
for m in a:
print(m.string)
excel的操作
- 写:
import openpyxl
book=openpyxl.Workbook()
sheet=book['Sheet']
for i in range(1,100):
cell=sheet.cell(i,1)
cell.value=str(i)
book.save("book1.xlsx")
- 读:
import openpyxl
book=openpyxl.load_workbook('book1.xlsx')
sheet=book.active
cell=sheet['c4']
cell=sheet.cell(4,3)
print(cell.value)
book.close()
数据可视化
import matplotlib.pyplot as ptl
import numpy
# 一张图变四张
fig,sub=ptl.subplots(2,2)
x=numpy.arange(0,2*numpy.pi)
x=numpy.linspace(0,2*numpy.pi,100)
y=numpy.sin(x)
sub[0,0].plot(x,y)
y=numpy.cos(x)
sub[0,1].scatter(x,y,s=1)
y=x
sub[1,1].plot(x,y)
x=numpy.linspace(-numpy.pi/2,numpy.pi/2,100)
y=numpy.tanh(x)
sub[1,0].plot(x,y)
ptl.grid()
ptl.savefig('num.jpg')
ptl.show()
网友评论