0

オンラインで見つけたpython 2.7 craigslistスクレーパーをpython 3.6で動作するように適応させようとしています。

しかし、Python スクリプトを実行するたびに、何も返されません。正しいhtmlタグをターゲットにしていないからですか? もしそうなら、どうすれば正しいhtmlタグをターゲットにできますか?

ここのコードのこの部分だと思います:

    for listing in soup.find_all('p',{'class':'result-row'}):
    if listing.find('span',{'class':'result-price'}) != None:

完全なスクリプトは以下にあります。

前もって感謝します。

import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin

URL = 'https://vancouver.craigslist.ca/search/sss?query=Vespa'
BASE = 'https://vancouver.craigslist.ca/'

response = requests.get(URL)

soup = BeautifulSoup(response.content,"html.parser")
for listing in soup.find_all('p',{'class':'result-row'}):
    if listing.find('span',{'class':'result-price'}) != None:
        price = listing.text[2:6]
        price = int(price)
        if price <=3600 and price > 1000:
            print (listing.text)
            link_end = listing.a['href']
            url = urljoin(BASE, link_end)
            print (url)
            print ("\n")
print('test')
4

1 に答える 1