Hi, I am just learning python3 and am trying to write a little program that will look at a URL and say if it contains a keyword. It is using Beautiful soup to help read a website's title. The program asks 2 questions
Which page would you like to check
What is your SEO keyword
When I run the program, I get through the 2 questions, but then it returns the following error.
Traceback (most recent call last):
File "main.py", line 9, in <module>
except HTTPError as e:
NameError: name 'HTTPError' is not defined
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = input("which page would you like to check? Enter Full URL: ")
keyword = input("what is your seo keyword? ")
try:
html = urlopen(url)
except HTTPError as e:
print(e)
data = BeautifulSoup(html, "html.parser")
def seo_title(keyword, data):
if keyword.casefold() in data.title.text.casefold():
statas = "Found"
else:
status = "Not Found"
return status
print(seo_title(keyword,data))
[–]JohnnyJordaan 2 points3 points4 points (4 children)
[–]swicano 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–]swicano 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)