#这个爬虫就是需要你给个链接就可以了,记住最好是用csdn的网址,如果你想要爬取一些学习的资料可以看看小编其它的代码,这个只适合于csdn
#只需要往这个里面复制链接就可以爬取出来它的子链接及标题了
def lianjie(i):
from urllib.request import urlopen
from bs4 import BeautifulSoup
k=i
#k = input()
def pa(html):
bs = BeautifulSoup(html, 'html.parser') # 解析网页
return bs
list = []
#这个片段是为了将文章进行处理,排除掉那些none还有JavaScript
try:
html = urlopen(k)
bs = pa(html)
hyperlink = bs.find_all('a')
for h in hyperlink:
hh = h.get('href')
if len(str(hh)) > 25:
list.append(hh)
except ValueError:
print('')
except Exception:
print("")
# 没有预先判断到的错误怎么办?
# ZeroDivisionError
finally:
# 无论是否有异常,都会执行的代码
print('')
for i in list:
try:
html = urlopen(i)
bs = BeautifulSoup(html, 'html.parser') # 解析网页
hyperlink = bs.find_all('title')
print(hyperlink, ':', i)
# print(bs.select('title'))
except ValueError:
print('')
except Exception:
print("")
# 没有预先判断到的错误怎么办?
# ZeroDivisionError
finally:
# 无论是否有异常,都会执行的代码
print('')
from urllib.request import urlopen
from bs4 import BeautifulSoup
k = input()
def pa(html):
bs = BeautifulSoup(html, 'html.parser') # 解析网页
return bs
list = []
# 这个片段是为了将文章进行处理,排除掉那些none还有JavaScript
try:
html = urlopen(k)
bs = pa(html)
hyperlink = bs.find_all('a')
for h in hyperlink:
hh = h.get('href')
if len(str(hh)) > 25:
list.append(hh)
except ValueError:
print('')
except Exception:
print("")
# 没有预先判断到的错误怎么办?
# ZeroDivisionError
finally:
# 无论是否有异常,都会执行的代码
print('')
for i in list:
lianjie(i)