To scrape keywords from a website, you can use the Python package called BeautifulSoup. Here is an example of how to do it:
Python
# Import the required libraries
import requests
from bs4 import BeautifulSoup
# Use the requests library to get the HTML content of the website
response = requests.get("http://www.example.com")
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, "html.parser")
# Find all the keywords on the page
keywords = soup.find_all("meta", {"name": "keywords"})
# Print the keywords
for keyword in keywords:
print(keyword["content"])
PythonThis code will get the HTML content of the website, parse it using BeautifulSoup, and find all the meta
tags with the attribute name
set to keywords
. It will then print the value of the content
attribute for each of these tags.
You can also use the find()
method instead of find_all()
to get only the first keyword on the page.
Keep in mind that not all websites use the meta
tag for keywords, so this approach may not work for all websites. Additionally, some websites may use different HTML tags or attributes for storing keywords, so you may need to adjust the code accordingly.