小编Mon*_*nty的帖子

Python从页面上的链接下载多个文件

我正在尝试从此站点下载所有PGN

我想我必须用来urlopen打开每个 url,然后urlretrieve通过从每个游戏底部附近的下载按钮访问它来下载每个 pgn。我是否必须BeautifulSoup为每个游戏创建一个新对象?我也不确定如何urlretrieve工作。

import urllib
from urllib.request import urlopen, urlretrieve, quote
from bs4 import BeautifulSoup

url = 'http://www.chessgames.com/perl/chesscollection?cid=1014492'
u = urlopen(url)
html = u.read().decode('utf-8')

soup = BeautifulSoup(html, "html.parser")
for link in soup.find_all('a'):
    urlopen('http://chessgames.com'+link.get('href'))
Run Code Online (Sandbox Code Playgroud)

python urllib beautifulsoup python-3.x

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

beautifulsoup ×1

python ×1

python-3.x ×1

urllib ×1