2021年6月4日星期五

pythonchallenge第4关

py3直接按照网上的代码会报错,爆string和byte 类型不一致的问题,需添加chardet模块进行转义。代码如下



#!/usr/bin/python3

#coding=utf-8

import re

import urllib.request

import time

import chardet


x = 400

url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345"

while x:

request = urllib.request.Request(url)

response = urllib.request.urlopen(request)

str = response.read()

str = str.decode('utf8')

print (str)

s = re.findall(r'the next nothing is (\d+)',str)

url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + s[0]

print (url)

x -= 1

time.sleep(3)

没有评论:

发表评论