Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Python How to get all the links from a website
SUBMITTED BY:
alemotta
DATE:
April 1, 2017, 11:11 p.m.
FORMAT:
Text only
SIZE:
448 Bytes
Raw
Download
Tweet
HITS:
1193
Go to comments
Report
Python How to get all the links from a website
This example will get all the links from any websites HTML code.
To find all the links, we will in this example use the urllib2 module together
with the re.module
import urllib2
import re
#connect to a URL
website = urllib2.urlopen(url)
#read html code
html = website.read()
#use re.findall to get all the links
links = re.findall('"((http|ftp)s?://.*?)"', html)
print links
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus