以下のWebページから複数のテーブルを取得しようとしています。しかし、すべてのテーブルが同じtrタグとtdタグにネストされているにもかかわらず、私のコードは最初のテーブルのみを取得しています。それが私の試みです:
url = "http://zipnet.in/index.php?page=missing_person_search&criteria=browse_all&Page_No=1"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
tables = soup.find('table', border=1)
for row in tables.findAll('tr'):
sleep (3)
col = row.findAll('td')
fields = col[0].string
details = col[1].string
record = (fields, details)
print (record)
ここで何が欠けていますか?
試してみて、そのページで利用可能なすべてのテーブル、特に必要なレコードを含むテーブルを入手してください。
import requests
from bs4 import BeautifulSoup
url = "http://zipnet.in/index.php?page=missing_person_search&criteria=browse_all&Page_No=1"
res = requests.get(url)
soup = BeautifulSoup(res.text, 'lxml')
for trow in soup.select("table#AutoNumber15"):
data = [[' '.join(item.text.split()) for item in tcel.select("td")]
for tcel in trow.select("tr")]
print(data)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加