Python之自动查询数据

2025-11-02 01:00:12

1、导入第三方类库,若不存在,则利用pip进行安装;

如输入:pip install ggplot;

整个import库为:

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from time import sleep

import time

import requests

import re

import sys

import xlwt

Python之自动查询数据

Python之自动查询数据

2、python的路径下包含firefox驱动geckodriver、selenium等文件,如下图所示:

Python之自动查询数据

3、设置初始url;

3、利用webdriver的火狐驱动打开火狐浏览器;

输入:

driver=webdriver.Firefox()

driver.maximize_window()

Python之自动查询数据

4、新建一个文本文件,输出结果:

如:

f = open("autoFtimage.txt", "w")

Python之自动查询数据

5、新爱趣建一个Excel表格;

如: sheet = workbook.add_sheet(modal,cell_overwrite_ok=True)

6、依次往表格里输出列名;

如:

sheet.write(0,0,'是否存在数据(1为是,0为否)')

sheet.write(0,1,'类型')

sheet.write(0,2,'起始时间')

sheet.write(0,3,'结束时间')

7、遍历url中的数据截醒,依次输出数据到表格里面;

如:

sheet.write(i,0,isExist)

sheet.write(i,1,modal)

sheet.write(i,2,beginDate)

sheet.write(i,3,endDate)

8、保存表格数据,并关闭文本文件;

如:

workbook.save(r'./2018EveryDayData.xlsx')

f.close()

9、运行方式:

1、在命令行输入:python autoSearch.py;

2、在针财倘python文件所在路径下新建可执行的bat文件,内容为:

start python autoSearch_everyday.py

Python之自动查询数据

10、在运行过程中,会自动产生geckodriver文件;

运行结束后,将产生2018EveryDayData.xlsx文件;

Python之自动查询数据

Python之自动查询数据

Python之自动查询数据

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢