我正在尝试调整我在网上找到的 python 2.7 craigslist scraper 以与 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')