python爬runoob目录链接栏

Posted on 2019-12-19 12:14  zhuyu123  阅读(174)  评论(0编辑  收藏  举报
import re
import requests
url='https://www.runoob.com/python3/python3.html'
response=requests.get(url)
html=response.text
response.encoding='utf-8'
dl=re.findall(r'<div class="design" id="leftcolumn">.*?</div>',html,re.S)[0]
tree=re.findall(r'title="(.*?)".*?href="(.*?)"',dl)
lst=[]
def get_data(link):
    lst.append(link)
    ht=requests.get(link)
    print('已下载',len(lst),'')
for tree_info in tree:
    url='https://www.runoob.com/python3{}\n'.format(tree_info[1])
    with open('D:\Desktop\测试\html.txt','a') as f:
        f.write(url)
    get_data(url)

Copyright © 2024 zhuyu123
Powered by .NET 9.0 on Kubernetes