我正在尝试修改我在网上找到的python2.7Craigslist刮板,使其与python3.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')发布于 2017-06-22 15:01:24
你是对的,这是可能的问题:
for listing in soup.find_all('p',{'class':'result-row'}):
if listing.find('span',{'class':'result-price'}) != None:这篇文章必须针对你正在抓取的特定网页进行编辑。您是否查看了页面的HTML并验证了这两行?如果没有,用鼠标右键点击页面并选择“查看页面源代码”。然后你必须找到你想要抓取的特定数据。
如果我想从html中的网页中抓取一些东西:
<div class='what'>hello</div>我将上面的代码更改为:
for listing in soup.find_all('div',{'class':'what'}):
# do somethinghttps://stackoverflow.com/questions/44687195
复制相似问题