Function in python for loop can only be run once?
伊谢尔伦
伊谢尔伦 2017-06-30 09:55:41
0
2
972
**这是源码,奇了怪了,最后那个for循环中的函数run()只能运行一次,求大神指点**
刚才有个大神回复了还是有点问题,一不小心把问题删除了,重新发布一下,不好意思

#coding=utf8
import itchat
import time
import re
import xian

def run(url):

    xian.parse(url)
    
    itchat.auto_login(hotReload=True)
    
    users = itchat.search_friends(name='risk')                  #获取对方UserName,返回一个列表
    print('========================================================================')
    user = users[0]['UserName']                                 #提取指定UserName
    print(user)
    
    f = open('/Users/Air/itchat/data2.txt')
    lines = f.readlines()                                           #读取全部内容
    print(lines)
    
    for i in range(100):
    itchat.send(lines[i], toUserName=user)                 #UserName需要用上面获取的自己修改
    
    print("Success")
    f.close()
    itchat.run()
    
for x in range(1,5):

    url1 = 'https://m.taobao.com/list/list.htm?'
    run(url1)
    time.sleep(10)
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
習慣沉默

I guess it is the last itchat.run() in run that causes the itchat service to be suspended. Due to the suspended service, the first time run() is called, it cannot exit, resulting in the subsequent Times forcannot continue to run.

小葫芦

itchat.run will hang, take itchat.autologin and itchat.run outside, and then start a sub-thread to run your own run function, but itchar.run must be placed after the sub-thread is started

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!