저는 파이썬에 조금 익숙하며 웹 페이지 (http://findanrd.eatright.org/listing/search?zipCode=page=1)에서 정보를 추출하려고합니다.서브 링크에서 데이터 추출하기
"정보 페이지"에서 모든 링크를 가져 오지만 그 정보를 추출하지 못합니다.
<div class="user-info-box clearfix">
<dl class="details-left">
<dl class="details-left">
<dl class="details-right">
<dd>26850 Providence Parkway, Suite 425</dd>
<dd>Novi, MI 48374</dd>
<dd>Email: [email protected]</dd>
<dd>
Website:
<a href="http://www.aartibatavia.com/" target="_blank">www.aartibatavia.com/</a>
</dd>
</dl>
나는 거리, 이메일 주소와 웹 페이지처럼, 위의 정보를 추출 할 수 있습니다. 내 코드는 다음과 같습니다.
import requests
from bs4 import BeautifulSoup
def nutrispider(max_pages):
page = 1
while page <= max_pages:
url = 'http://findanrd.eatright.org/listing/search?zipCode=&page=' + str(page)
source_code = requests.get(url)
text = source_code.text
soup = BeautifulSoup(text)
x = 0
while x<=19:
rows = soup.findAll('tr', {'data-index':x})
for row in rows:
link_elm = row.find('div', {'class':'search-address-list-address'}).a
link = 'http://findanrd.eatright.org' + link_elm['href']
users = soup.findAll('div', {'class': 'user-info-box clearfix'})
for user in users:
information = user.find('dd')
text = information.get_Text()
print(text)
print(link)
x += 1
page += 1
nutrispider(1)
현재 오류는 없지만 정보가있는 서브 페이지에 대한 링크 만 인쇄됩니다.
A * 서브 * 링크 같은 것은 없다. 링크와 페이지가 있습니다. –
그럼 나는 메인 페이지를 통해 접근하는 페이지를 의미했습니다 : mainpage : http://findanrd.eatright.org/listing/search?zipCode=page=1 페이지 "behind": http://findanrd.eatright.org/listing/details/5891? zipCode = page % 3D1 – Markus
그리고 어디에 문제가 있습니까? 목록을 사용하십시오. –