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())
何が問題なのですか?このコードは2番目のウェブサイトの後についています。リスト内の各ウェブページから電話番号を抽出する必要がありますself.urls
複数のWebページをPythonで削る
あなたはすべてのエラーを取得している場合は、私はあなたのコードを試してみただけでなく – csharpcoder
それを投稿してください、すべてが正常に動作します。 [9.3秒で終了] – ventik
エラーはありません。 Pythonシェルは作業をしていますが、何も返さないのです。私はPython 3.6でSpyderを使用します。私は5分以上待っていて何も起こらない。 – FootAdministration