问题遇到的现象和发生背景
运用pyautogui自动下载软件上的资料,为什么遍历代码列表,显示不可迭代的对象
用代码块功能插入代码,请勿粘贴截图
```python
import pyautogui
import pandas as pd
pyautogui.PAUSE = 1
#读取全部A股(标的股票代码)excel
data_read = pd.read_excel("F:\\gupiaoziliao\\全部A股.xlsx")
#清洗证券代码,去掉'.'和字母,只保留数字
code_column = list(data_read['证券代码'])
for i in range(len(code_column)):
code_column[i] = code_column[i].split('.')[0]#先分割,再取子列表中的第一个元素
# 1.点击ifind图标
pyautogui.click(175,1055,button = 'left')
# 1.点击搜索框
def dianjidaimasousuokuang():
#在搜索框内输入股票代码,并按回车键
screen_img = pyautogui.screenshot()
screen_img.save('F:\\PythonData\\image\\screen_img.png')
left, top, width, height = pyautogui.locateOnScreen('F:\\PythonData\\image\\sousuokuang.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
# 2.输入代码,并按回车键
def shurudaima(code):
pyautogui.typewrite(code, 0.5)
pyautogui.press('enter')
# 3.点击导出数据按钮
def dianjidaochushuju():
screen_img = pyautogui.screenshot()
screen_img.save('F:\\PythonData\\image\\screen_img.png')
left, top, width, height = pyautogui.locateOnScreen('F:\\PythonData\\image\\daochushuju.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
# 4. 点击路径输入框
def dianjibaocunlujing():
screen_img = pyautogui.screenshot()
screen_img.save('F:\\PythonData\\image\\screen_img.png')
left, top, width, height = pyautogui.locateOnScreen('F:\\PythonData\\image\\baocun\\baocunweizhi.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
# 5.输入保存路径
def shurulujing():
pyautogui.typewrite('F:\\gupiaoziliao', 0.5)
pyautogui.press('space')
# 6.点击转到按钮
def dianjizhuandao():
screen_img = pyautogui.screenshot()
screen_img.save('F:\\PythonData\\image\\screen_img.png')
left, top, width, height = pyautogui.locateOnScreen('F:\\PythonData\\image\\baocun\\zhuandao.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
# 7.点击文件名输入框
def dianjiwenjianming():
screen_img = pyautogui.screenshot()
screen_img.save('F:\\PythonData\\image\\screen_img.png')
left, top, width, height = pyautogui.locateOnScreen(
'F:\\PythonData\\image\\baocun\\wenjianming.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
# 8.输入文件名,并点击空格键
def shuruwenjingming(code):
pyautogui.typewrite(code+'-gongsijieshao', 0.5)
pyautogui.press('space')
# 9.点击保存按钮
def dianjibaocunanniu():
screen_img = pyautogui.screenshot()
screen_img.save('F:\\PythonData\\image\\screen_img.png')
left, top, width, height = pyautogui.locateOnScreen(
'F:\\PythonData\\image\\baocun\\baocunjian.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
#封装函数
i = 0
while i < len(code_column):
# 1.点击搜索框
dianjidaimasousuokuang()
# 2.输入代码,并点击回车
shurudaima(code_column[i])
# 3.点击导出数据按钮
dianjidaochushuju()
#4.点击路径输入框
dianjibaocunlujing()
# 5.输入保存路径
shurulujing()
# 6.点击转到按钮
dianjizhuandao()
# 7.点击文件名输入框
dianjiwenjianming()
# 8.输入文件名,并点击空格键
shuruwenjingming(code_column[i])
# 9. 点击保存按钮
dianjibaocunanniu()
i += 1
运行结果及报错内容
Traceback (most recent call last):
File "F:\PythonData\test.py", line 86, in <module>
dianjidaochushuju()
File "F:\PythonData\test.py", line 33, in dianjidaochushuju
left, top, width, height = pyautogui.locateOnScreen('F:\\PythonData\\image\\daochushuju.png')
TypeError: cannot unpack non-iterable NoneType object