然而,这并不是因为我试图在我的代码中实现这个答案(对那个线程的操作有效,但对我不起作用)。在
我的职能是:def define_word(user_define_input):
srch = str(user_define_input[1])
output_word=urllib.request.urlopen("http://dictionary.reference.com/browse/"+srch+"?s=t")
output_word=output_word.read()
items=re.findall('
for output_word in items:
y=output_word.replace('','')
m=re.findall('at Dictionary.com, a free online dictionary with pronunciation, synonyms and translation. Look it up now! "/>',z)
if m==[]:
if z.startswith("Get your reference question answered by Ask.com"):
print ("Word not found!")
else:
print (z)
else:
print ("Word not found!")
注:
^{pr2}$
另外,这包含了一点HTML:/抱歉,但这是另一个答案使用的。在
所以,当我尝试使用这个错误时:File "/Users/******/GitHub/Multitool/functions.py", line 104, in define_word
items=re.findall('
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/re.py", line 210, in findall
return _compile(pattern, flags).findall(string)
TypeError: can't use a string pattern on a bytes-like object
注:
第104行函数.py是:items=re.findall('
第210行复制是此函数的最后一行:def findall(pattern, string, flags=0):
"""Return a list of all non-overlapping matches in the string.
If one or more capturing groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern
has more than one group.
Empty matches are included in the result."""
return _compile(pattern, flags).findall(string) #line 210
如果这里面有什么不清楚的地方,请告诉我(我不确定要为这个添加什么标签:/)。提前感谢您:)您可以随意更改任何内容,甚至重新编写整个内容,但一定要使用变量/列表:define_word(函数名)
用户定义输入
添加:output_word = output_word.decode()
或者改变output_word = output_word.read().decode('iso-8859-2')
在输入以下内容时给出:定义测试:Test definition, the means by which the presence, quality, or genuineness of anything is determined; a means of trial.
Word not found!