【发布时间】:2016-02-16 19:34:46
【问题描述】:
我想抓取automatedtheboringstuff.com 并输出所有练习项目并将它们存储到一个文件中。最终,我希望我的代码从一页移动到下一个搜索练习项目的页面,但现在我只是想让beautifulsoup 将练习项目输出到一个页面上。但它不起作用。我只是得到一个空白 []。
这是我目前的代码。
def pageDownload(webPage):
# Downloads the page
while not url.endswith('appendixc'):
print('Downloading page %s...' % url)
res = requests.get(url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text)
return soup
def getProjects(downloadedPage):
# gets the projects contents
soup = downloadedPage
book = soup.find_all('p', attrs={'title' : 'Practice Projects'})
print(book)
【问题讨论】:
-
您在哪个页面上看到
p块将title设置为Practice Projects? (我在网站上第一眼没看到) -
另外,你有一段时间内的回报 - 这是故意的吗?
标签: python python-3.x web-scraping beautifulsoup