📌  相关文章
📜  如何在链接 beautifulsoup 中找到 pdf 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:28.298000             🧑  作者: Mango

代码示例1
# Find links to pdf files in HTML with BeautifulSoup

import urllib2
from bs4 import BeautifulSoup
my_url = 'http://slav0nic.org.ua/static/books/python/'
html=urllib2.urlopen(my_url).read()
sopa = BeautifulSoup(html)
current_link = ''
for link in sopa.find_all('a'):
  current_link = link.get('href')
    if current_link.endswith('pdf'):
      print('Tengo un pdf: ' + current_link)