【发布时间】:2018-02-26 02:11:33
【问题描述】:
我想我必须使用urlopen 打开每个网址,然后使用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'))
【问题讨论】:
标签: python python-3.x beautifulsoup urllib