0
我正在嘗試改編一個python 2.7 craigslist scraper,我在網上發現使用python 3.6。改編Craigslist Scraper Python
但每次運行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')