from bs4 import BeautifulSoup
import urllib, time
class scrap(object):
def __init__(self):
self.urls = ['https://www.onthemarket.com/for-sale/property/wigan/', 'https://www.onthemarket.com/for-sale/property/wigan/?page=1', 'https://www.onthemarket.com/for-sale/property/wigan/?page=2', 'https://www.onthemarket.com/for-sale/property/wigan/?page=3', 'https://www.onthemarket.com/for-sale/property/wigan/?page=4', 'https://www.onthemarket.com/for-sale/property/wigan/?page=6']
self.telephones = []
def extract_info(self):
for link in self.urls:
data = urllib.request.urlopen(link).read()
soup = BeautifulSoup(data, "lxml")
for tel in soup.findAll("span", {"class":"call"}):
self.telephones.append(tel.text.strip())
time.sleep(1)
return self.telephones
to = scrap()
print(to.extract_info())
무엇이 잘못 되었나요? 이 코드는 두 번째 웹 사이트 뒤에 매달려 있습니다. 목록의 각 웹 페이지에서 전화 번호를 추출해야합니다. self.urls
파이썬으로 여러 웹 페이지 긁기
오류가 발생하면 – csharpcoder
코드를 사용해 보았습니다. 모든 것이 잘 작동합니다. [9.3에서 끝났습니다] – ventik
오류가 없습니다. 파이썬 셸 작업을하고 있지만 아무것도 반환하지 않습니다. 나는 Spyder를 Python 3.6과 함께 사용한다. 나는 5 분 이상 기다리고 아무 것도 일어나지 않는다. – FootAdministration