Address
304 North Cardinal St.
Dorchester Center, MA 02124
Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM
Address
304 North Cardinal St.
Dorchester Center, MA 02124
Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM
Here’s a quick writeup for how to grab a page title with Python.
This will be another shorter post, as I have some last-minute work travel coming up.
I promise that there are more vulnserver posts coming, I just need some time to finish them.
Other than that, I was on an engagement recently and wanted to grab the title for a huge list of webpages. Note that the http-title nmap script works great, but I didn’t have nmap on the box that I was using.
As the introduction mentioned, I was wanting to grab the title for a list of web pages using Python. Similar to some of my previous tools, I decided to use BeautifulSoup for this.
This was far easier than I expected, and I could probably build it out into a real web enumeration tool.
C:\Users\doyler\Documents>py grabTitle.py Page URL and Title ----------------------------------------------------------------- http://www.google.com = Google http://www.cnn.com = CNN - Breaking News, Latest News and Videos
You can find the entire script below, and it is fairly straightforward. It will connect to a URL using the requests library, and then parse out the title using BeautifulSoup.
This only supports a list of URLs for now, but could easily be extended to support an input file of URLs/IPs.
import requests from bs4 import BeautifulSoup def main(): print("\nPage URL and Title") print("-----------------------------------------------------------------") urls = ['http://www.google.com', 'http://www.cnn.com'] for url in urls: r = requests.get(url) soup = BeautifulSoup(r.text, 'html.parser') print(url + " = " + soup.title.string) if __name__ == "__main__": main()
I know this was a shorter post than normal, but I’m still trying to catch up on everything.
Let me know if you would like to see any real features added to this script. If so, then I can probably update it and turn it into a useful enumeration tool.
Finally, you can find the code and updates in my GitHub repository.
Ray Doyle is an avid pentester/security enthusiast/beer connoisseur who has worked in IT for almost 16 years now. From building machines and the software on them, to breaking into them and tearing it all down; he’s done it all. To show for it, he has obtained an OSCE, OSCP, eCPPT, GXPN, eWPT, eWPTX, SLAE, eMAPT, Security+, ICAgile CP, ITIL v3 Foundation, and even a sabermetrics certification!
He currently serves as a Senior Staff Adversarial Engineer for Avalara, and his previous position was a Principal Penetration Testing Consultant for Secureworks.
This page contains links to products that I may receive compensation from at no additional cost to you. View my Affiliate Disclosure page here. As an Amazon Associate, I earn from qualifying purchases.