import re
import urllib
url = 'http://news.legacyvn.com'
link_list = []
url_pattern = (r'''(?x)((href)="/(\w+[:.]?){2,}(/?|[^ \n\r"']+[\w/!?.=#])(?=[\s\.,>)"'\]]))''')
try:
page = urllib.urlopen(url).read()
link_list = re.findall(url_pattern, page)
except Exception, e:
print e
for link in link_list:
urlst = link[0].replace('href="', url)
print 'Checking:', urlst, '...',
try:
page = urllib.urlopen(urlst).read()
print 'OK!'
except IOError, e:
print 'PROBLEM:', e
link_list2 = []
url_pattern2 = (r'''(?x)((src)="/(\w+[:.]?){2,}(/?|[^ \n\r"']+[\w/!?.=#])(?=[\s\.,>)"'\]]))''')
try:
page = urllib.urlopen(url).read()
link_list2 = re.findall(url_pattern2, page)
except Exception, e:
print e
for link2 in link_list2:
urlst2 = link2[0].replace('src="', url)
print urlst2
try:
page = urllib.urlopen(urlst2).read()
print 'OK!'
except IOError, e:
print 'PROBLEM:', e
Em muốn check toàn bộ link trong web trên nhưng code trên chỉ check được trang chủ. Mọi người giúp e với ạ
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?