# This is a sample Python script.
import requests
from bs4 import BeautifulSoup
import xlwt
f = xlwt.Workbook()
sheet = f.add_sheet("work")
headers={}
r=requests.get("http://localhost:8080/",None,headers=headers)
r.encoding = "utf-8"
if r.status_code == 200:
str = BeautifulSoup(r.text,'html.parser')
item = str.select(".item")
print(len(item))
print("-"*50)
for i in range(len(item)):
title = item[i].select(".title")[0].text
print(title)
years = item[i].select(".years")[0].text
print(years)
sal = item[i].select(".sal")[0].text
sheet.write(i,0,title)
sheet.write(i,1,years)
sheet.write(i,2,sal)
f.save("./text.xls")
爬虫Python
最新推荐文章于 2024-04-01 13:30:49 发布