How Do You Programmatically Search Hyperlinks on a Given Webpage?

Problem scenario
You have a web page that you access from the front-end (e.g., a web browser). You want to see if there is a hyperlink on the page that goes to a certain URL. You know the web page and the URL, but you are not sure if a hyperlink on the website has such a link. What should you do?

Solution
Use the curl command. From a Linux command prompt, type this:

# Replace <URL of web page> with the web page you that has hyperlinks
# Replace "stringYouSearch" with an all-lowercase pattern that the hyperlink you are searching for
curl http://<URL of web page> | grep -i stringYouSearch

Leave a comment

Your email address will not be published. Required fields are marked *