1
我試圖獲得使用從HTML文件的正則表達式的數據中提取源代碼的HTML文件,通過執行以下代碼:使用python3.1 urllib.request裏
返回一個錯誤:
File "extract.py", line 33, in extract_words
match = re.findall("<tr>\s*<td>([\w\s.;'(),-/]+)</td>\s+<td>([\w\s.,;'()-/]+)</td>\s*</tr>", text)
File "/usr/lib/python3.1/re.py", line 192, in findall
return _compile(pattern, flags).findall(string)
TypeError: can't use a string pattern on a bytes-like object
當在IDLE進一步試驗,我注意到uf.read()確實返回第一次調用它的HTML源代碼。但之後,它返回一個-b「'。有什麼辦法可以解決這個問題嗎?