我是否能夠運行 while 回圈并添加到下面的索引以收集頁面上的所有奇數索引?
基本上,我想跳過所有偶數索引并列印奇數索引,而不是像 [1]、[3]、[5] 等一樣在下面的星號中一遍又一遍地寫相同的行。
有沒有辦法寫一個while回圈并添加到索引號?
謝謝!!
'''
import bs4
from bs4 import BeautifulSoup
import requests
import lxml
vegas_insider = requests.get('https://www.vegasinsider.com/nfl/matchups/', 'r').text
soup = BeautifulSoup(vegas_insider, 'lxml')
**team =soup.find_all('a', class_ = 'tableText')[1].text**
print(team)
'''
uj5u.com熱心網友回復:
teams = [team.text for team in soup.find_all('a', class_ = 'tableText')[1::2]]
或列印,
for team in soup.find_all('a', class_ = 'tableText')[1::2]:
print(team)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/320989.html
上一篇:當Allow-Credentials設定為true時,為什么我不能在Access-Control-Allow-Headers上使用通配符*?
