1
我想從列表中的每個團隊獲得團隊成員的數量,現在我得到所有的團隊鏈接,而不是獲取我想獲得的所有鏈接至少有5名團隊成員的團隊的鏈接。我會怎麼做呢?我試過,但迄今爲止沒有任何工作。試圖從使用美麗的湯的網站顯示文本
import time
import requests
from bs4 import BeautifulSoup
def get_all(url, base):
r = requests.get(url)
page = r.text
soup = BeautifulSoup(page, 'html.parser')
for team_links in soup.select('div.details h3 a'):
yield base + team_links['href']
next_page = soup.find('div', {'class': 'pages'}).find('span', text='Next')
while next_page:
# Gives the server a break
time.sleep(0.2)
r = requests.get(BASE_URL + next_page.find_previous('a')['href'])
page = r.text
soup = BeautifulSoup(page)
for team_links in soup.select('div.details h3 a'):
yield BASE_URL + team_links['href']
next_page = soup.find('div', {'class': 'pages'}).find('span', text='Next')
if __name__ == '__main__':
BASE_URL = 'http://www.gosugamers.net'
URL = 'http://www.gosugamers.net/counterstrike/teams'
for link in get_all(URL, BASE_URL):
print (link)
你想什麼如果有'4(待定:1)'情況(不確定是否會發生)? – alecxe
我只想拒絕它,如果有任何掛起。它需要是一個由5人組成的團隊,或者繼續 – DJRodrigue
好的,在代碼中完全用這個邏輯進行更新。 – alecxe