私は私のウェブサイトからページのdiscriptionを読みたいです。ここでは、コードですPythonどのようにウェブからポルトガル語の文字を取得する
import urllib.request
import re
req = urllib.request.Request("http://sorelogios.pt", headers={'User-Agent': 'Mozilla/5.0'})
htmltext = urllib.request.urlopen(req).read()
if htmltext is None:
print("nada")
else:
regex='<title>(.+?)</title>'
pattern=re.compile(regex)
price=pattern.findall(str(htmltext))
print(price[0])
regex='<meta name="description" content=(.+?)/>'
pattern=re.compile(regex)
prices=pattern.findall(str(htmltext))
print(prices[0])
私の問題は私のWebページにはポルトガルの文字を持っており、私はこの問題を解決し、元の文字を取得することができますどのように私は REL \ XC3 \ xb3gios homemロハオンライン のような何かを得るのですか? ありがとう
'str()'、* decode *は使わないでください。正しい正規表現ではなく、[BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)のような適切なHTMLパーサーを使用すると、Unicodeの結果が無料で返されます。 –