-1
ウェブサイトとキーワードの入力を受け取り、その単語のウェブサイトのソースコードを読み取るプログラムを書く必要があります。私はそれをコード化して、単語の多くのバリエーションを検出する必要があります(例えば、こんにちは、こんにちは、こんにちは!)、これを行う方法がわかりません。正確な入力を検出するためにこれまでのようにコード化しましたが、複数のバリエーションを取得する方法がわかりません。どんな助けでも大歓迎です、ありがとう!ソースコードから単語のバリエーションを見つける方法(python 3)
def main():
[n,l]=user()
print("Okay", n, "from", l, ", let's get started.")
webname=input("What is the name of the website you wish to browse? ")
website=requests.get(input("Please enter the URL: "))
txt = website.text
list=txt.split(",")
print(type(txt))
print(type(list))
print(list[0:10])
while True:
numkey=input("Would you like to enter a keyword? Please enter yes or no: ")
if numkey=="yes":
key=input("Please enter the keyword to find: ")
else:
newurl()
break
find(webname,txt,key)
def find(web,txt,key):
findtext=txt
list=findtext.split(sep=" ")
count = 0
for item in list:
if item==key:
count=count+1
print("The word", key, "appears", count, "times on", web)
def newurl():
while True:
new=input("Would you like to browse another website? Please enter yes or no: ")
if new=="yes":
main()
else:
[w,r]=experience()
return new
break
def user():
name=input("Hello, what is your name? ")
loc=input("Where are you from? ")
return [name,loc]
def experience():
wordeval=input("Please enter 3 words to describe the experience, separated by spaces (ex. fun cool interesting): ")
list=wordeval.split(sep=" ")
rate=eval(input("Please rate your experience from 1-10: "))
if rate < 6:
print("We're sorry you had a negative", list[0], "and", list[2], "experience!")
else:
print("Okay, thanks for participating. We're glad your experience was", list[1], "!")
return[wordeval,rate]
main()
「複数のパターン」とは何ですか?それを定義し、[最小、完全で、検証可能な例](http://stackoverflow.com/help/mcve)を提供してください。 – Prune
find()では、 "hello"のような多くの形式でソースコード内のキーワードとして "hello"を区別することができます。または "こんにちは、"。今すぐ正確な構文で単語を検出することができます。申し訳ありません – Hannah