【发布时间】:2015-07-09 15:11:40
【问题描述】:
我正在创建一个脚本来获取来自 funanimation 的新剧集。所以,我写了这个简单的脚本。
import requests
from bs4 import BeautifulSoup
import subprocess
r = requests.get('http://www.funimation.com/videos/episodes')
soup = BeautifulSoup(r.text)
print soup.title
subtitles = soup.findAll('div',{'class':'item-resume-info clearfix'})
for show in subtitles:
x = show.find_all('a', limit=1)
for a in x:
url = a['href']
file = open("LatestLink.txt", "w")
file.write(url)
file.close()
如您所见,它从 hompage 获取内容并向我显示链接。它正在工作并给我链接。但是,它给了我所有的链接。即使我限制了输出,它仍然显示 20 个链接。为什么会发生这种情况?当我将其写入文件时,它只会打印一个链接以及他们页面上最旧版本的链接。
我如何对结果进行排序或将它们限制为 1.?
【问题讨论】:
标签: python python-2.7 request beautifulsoup