xiaobei206 发表于 2019-1-20 23:08:19

LOC云函数挂机求指导,反正我看不懂。。。

Error 4xx Client Errors 登录后返回的这个页面

似毛非毛 发表于 2019-1-21 08:33:44

最近规则改了吧

fl20002 发表于 2019-1-20 23:20:25

s.get和s.post要带headers,把agent和ref属性带上

laofanne 发表于 2019-1-20 23:41:49

错误提示是说
19行这里的正则没有匹配到东西 re.search(r'积分: (\d+).+?', user_info) 为空
所以报NoneType没有group属性的错误

你只能一步一步往上查了

yjsx86 发表于 2019-1-21 00:22:31


yjsx86 发表于 2019-1-21 00:22

错误提示是说
19行这里的正则没有匹配到东西 re.search(r'积分: (\d+).+?', user_info) 为空
所以报NoneTyp ...
就是我说的,要带headers,楼主应该跟我一样用的loc大佬的代码。

laofanne 发表于 2019-1-21 00:50:24

[*]# -*- coding: utf8 -*-
[*]
[*]import requests
[*]import re
[*]from urllib.parse import quote
[*]from datetime import *
[*]bjtime=str(datetime.utcnow().replace(tzinfo=timezone.utc).astimezone(timezone(timedelta(hours=8)))).split('.')
[*]
[*]
[*]def start():
[*]    s = requests.session()
[*]    username = '账号账号账号账号'
[*]    password = '密码密码密码密码'
[*]
[*]    headers={
[*]      'Host': 'www.hostloc.com',
[*]      'Connection': 'keep-alive',
[*]      'Cache-Control': 'max-age=0',
[*]      'Origin': 'https://www.hostloc.com',
[*]      'Upgrade-Insecure-Requests': '1',
[*]      'Content-Type': 'application/x-www-form-urlencoded',
[*]      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',
[*]      'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
[*]      'Referer': 'https://www.hostloc.com/forum.php',
[*]      'Accept-Encoding': 'gzip, deflate',
[*]      'Accept-Language': 'zh-HK,zh;q=0.9,zh-CN;q=0.8,en-US;q=0.7,en;q=0.6,zh-TW;q=0.5'
[*]    }
[*]    login_url = 'https://www.hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'
[*]    s.post(login_url, {'fastloginfield':'username','quickforward':'yes','handlekey':'1s',"username": username, 'password': password}, headers=headers)
[*]
[*]    user_info = s.get('https://www.hostloc.com/home.php?mod=spacecp&ac=credit', headers=headers).text
[*]
[*]    current_money = re.search(r'积分: (\d+).+?', user_info).group(1)
[*]    print("用户%s,签到前你的积分为%s" % (username, current_money))
[*]
[*]    for i in range(20359, 20370):
[*]      s.get('https://www.hostloc.com/space-uid-%s.html' % i, headers=headers)
[*]
[*]    new_money = s.get('https://www.hostloc.com/home.php?mod=spacecp&ac=credit', headers=headers).text
[*]    new_money = re.search(r'积分: (\d+).+?', new_money).group(1)
[*]
[*]    print("用户%s,签到后你的积分为%s" % (username, new_money))
[*]
[*]
[*]def main_handler(event, context):
[*]    return start()
[*]
[*]
[*]if __name__ == '__main__':
[*]    start()
[*]复制代码

xiaobei206 发表于 2019-1-21 00:22:00


blanco 发表于 2019-1-21 02:44

大佬。你这个好像不行~

blanco 发表于 2019-1-21 01:55:24

战略mark
似毛非毛 发表于 2019-1-21 08:32

大佬。你这个好像不行~
刚在良心云试了下,用 Python3.6,还要配置超时,改成 10s 测试可以成功。

似毛非毛 发表于 2019-1-21 02:44:15

搞了半天没搞定。没去管它。今天自己好了。。
页: [1]
查看完整版本: LOC云函数挂机求指导,反正我看不懂。。。