我想我必须用来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)