私は簡単な単語/文ファインダーをやろうとしています。ウェブサイトでの文章の検索方法は?
はこれを試みた:それは罰金しかし、url
についての説明働くよう
import urllib
from urllib import request
url = "https://fotka.com/profil/k"
word = "Nie ma profilu"
def search_website(url, word):
page = urllib.request.urlopen(url)
phrase_present = False
for i in page:
if bytes(word, encoding='utf8') in i:
phrase_present = True
print(i)
return phrase_present
finder = search_website(url, word)
print(finder)
が見えます。 ブラウザで開く場合:
url = "https://fotka.com/profil/kkkk"
ありページにそのようなword
ではありません、それはまだTrue
を返します。
url = "https://fotka.com/profil/k"
確かに戻っTrue
のでword
存在を探索していますが、開いている場合があります。
私は、なぜこの問題を回避するための任意のアイデアを
誰もが知っている... url
が異なるが、それは同じである変数page
のとどちらの場合も、コンテンツチェックしていますか?
のためのあなたの解決策になるかもしれない、あなたはまた、 're.MULTILINE'と私はより理解しやすいように私の質問の内容を変更した –
' re.DOTALL'フラグを見てしたい場合があります。 – Emejcz