どのように私はアクセスしない<tr> tags inside <tbody>
使用find_all
してfor
、それぞれがあるためループ<tr>
互いに独立しているようだし、代わりのクラスを持っている'even'
と'odd'
。で渡すことができる引数は2つだけfind_all
です。すなわちfind_all('tr', class_='odd')
または(even)
また、それぞれの1番目、3番目、4番目、6番目にのみアクセスするにはどうすればよいですか。タグにはIDまたはクラスがありません。
[from bs4 import BeautifulSoup
import requests
src_code = requests.get('https://bschool.careers360.com/colleges/ranking/2018').text
soup = BeautifulSoup(src_code, features="html.parser")
i = 1
for trr in soup.find_all('tr', class_='odd'):
i+=1
college = trr.td.a.text
print(college)
if i%2==0:
class_='even'
else:
class_='odd'][1]
find_all("tr",class_=['odd','even'])
これにより、すべてのtrタグが取得され、次にタグ付きのtdタグとタグのテキストが取得されます。
from bs4 import BeautifulSoup
import requests
src_code = requests.get('https://bschool.careers360.com/colleges/ranking/2018').text
soup = BeautifulSoup(src_code, features="html.parser")
alltr=soup.find_all("tr",class_=['odd','even'])
for x in alltr:
print(x.td.a.text)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加