にだから私の割り当ては、すべてのWebページからのデータと印刷物の形式のすべてのハイパーリンクを読み取るプログラムを作成することです私のインストラクターの検索ハイパーリンクは、Python 3
from urllib.request import urlopen
def findTitle(webpage):
encoding = "utf-8"
for webpagestr in webpage:
webpagestr = str(webpagestr,encoding)
if "<title>" in webpagestr:
indexstart = webpagestr.find("<title>")
indexend = webpagestr.find("</title>")
title = webpagestr[indexstart+7:indexend]
return title
return title
def H1headings(webpage):
encoding = "utf-8"
for webpagestr in webpage:
webpagestr = str(webpagestr,encoding)
if "<h1>" in webpagestr:
indexstart = webpagestr.find("<h1>")
indexend = webpagestr.find("</h1>")
heading = webpagestr[indexstart+4:indexend]
print(heading)
def main():
address = input("Enter URL to find title and more information: ")
try:
webpage = urlopen(address)
title = findTitle(webpage)
print("Title is", title)
H1headings(webpage)
webpage.close()
except Exception as exceptObj:
print("Error: ", str(exceptObj))
main()
私はこのプログラムを実行すると、それを入力するURLを、私を可能にするが、それは私を与えた後: エラー:ローカル変数「タイトル」割り当て
前に参照さが、私はそれが何を意味するのかわかりません。
その後、私は置かれたとき、私の試みの1:
def findTitle(webpage):
title = "Not Found"
encoding = "utf-8"
は、プログラムを実行した、それは私を与える:
Enter URL to find title and more information: http://jeremycowart.com
Title is not found
<a href="http://jeremycowart.com">Jeremy Cowart</a>
それは私が探しているものですが、私は私は信じていますタイトルと見出しとリンクテキストがあるとします。
私は近づいてきましたが、わかりません。どんな助けもありがとう!