# coding:utf-8
'''
获取验证码自动登录
'''
import openpyxl
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import time
import re
import random
import pandas as pd
from openpyxl import load_workbook
import xlsxwriter as xw
import numpy as np
import xlwt
###填写需要爬取文字的url
url=''
brower=webdriver.Chrome()
brower.get(url)
time.sleep(5)
elements=brower.find_elements(by=By.XPATH,value="//a[@class='el']/div/span[1]")
money=brower.find_elements(by=By.XPATH,value="//p[@class='info']/span[1]")
workers=[]
moneys=[]
for i in elements:
worker=i.text
workers.append(worker)
for j in money:
money=j.text
moneys.append(money)
shuju=dict(zip(workers,moneys))
####方法一:保存到表格中
file=xlwt.Workbook('encoding=utf-8')
sheet1=file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet1.write(0,0,"序号")
sheet1.write(0,1,"工作")
sheet1.write(0,2,"月薪")
for i in range(len(workers)):
sheet1.write(i+1,0,i)
sheet1.write(i+1,1,workers[i])
sheet1.write(i+1,2,moneys[i])
file.save(r'C:\Users\Administrator\Desktop\data1.xlsx')
#####方法二:保存到表格中
dic={"worker":workers,"mone":moneys}
df=pd.DataFrame(dic)
print(df)
df.to_excel(r'C:\Users\Administrator\Desktop\data1.xlsx')
python爬取一些文字信息并保存到表格
原创
©著作权归作者所有:来自51CTO博客作者mb642e31a7373ff的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:使用python简单的爬取图片
下一篇:python分析excel数据
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章