<分区>
我正在做 python 挑战并试图熟悉 python,所以没有看答案,我尝试使用 python 的 url 阅读器来读取 html,然后找到所需的字母。但是在下面的代码中我得到一个错误,它最初是 python 3 urllib.request 但在解决它之后我得到一个新的错误:
<module> print ("".join(re.findall("[A-Za-z]", data))) File "C:\Python34\lib\re.py", line 210, in findall return _compile(pattern, flags).findall(string) TypeError: can't use a string pattern on a bytes-like object
现在我试着在谷歌上查找这个错误,但我得到的只是关于 json,我不应该需要它?我的 python 不是那么强大,所以也许我做错了?
#Question 2 - find rare characters
import re
import urllib.request
data = urllib.request.urlopen("http://www.pythonchallenge.com/pc/def/ocr.html")
mess = data.read()
messarr = mess.split("--")
print ("".join(re.findall("[A-Za-z]", data)))
#Question 3 - Find characters in list
page = urllib.request.urlopen("http://www.pythonchallenge.com/pc/def/equality.html")
mess = page.read()
messarr = mess.split("--")
print ("".join(re.findall("[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]+", page)))