#coding=utf-8

from bs4 import BeautifulSoup
import urllib.request
for i in range(1,54):
    url = "http://www.cnblogs.com/php-linux/?page="+str(i)
    res = urllib.request.urlopen(url)

    soup = BeautifulSoup(res,'lxml')
    book_div = soup.find(attrs={'id':"mainContent"})
    book_a = book_div.findAll(attrs={"class":'postTitle2'})
    f = open('a.txt',"a",encoding='utf8')
    for book in book_a :
        f.write(book.string+str("链接:")+ str(book.get('href')) + "\n")
    f.close()
    print("保存成功"+ book.string+str("链接:")+ str(book.get('href')))

  

相关文章:

  • 2021-12-26
  • 2021-09-02
  • 2021-09-09
  • 2021-08-19
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2022-12-23
  • 2021-11-29
  • 2022-01-01
  • 2021-07-24
  • 2022-01-14
  • 2021-11-30
相关资源
相似解决方案