刮人生……斗争是真实的!
当站点更改其布局时,通常可能会更改元素和类名。您想仔细检查更新并修复刮板中使用与页面元素、类名称等相关的硬编码值的任何内容,这些值可能已更改
快速检查页面显示您正在抓取的信息位于不同的结构中:
<div class="v-card">
<div class="media-thumbnail"><a class="media-thumbnail-wrapper chain-img" href="/milwaukee-wi/mip/7-eleven-471900245?lid=471900245"
data-analytics="{"click_id":509}" data-impressed="1"><img class="lazy" alt="7-Eleven" src="//i2.ypcdn.com/blob/c625613c07118f48908d08ec3c5f5f9a9f813850_40.png?074020d"
data-original="//i2.ypcdn.com/blob/c625613c07118f48908d08ec3c5f5f9a9f813850_40.png?074020d" width="40"
height="40" style="display: block;"><noscript><img alt="7-Eleven" src="//i2.ypcdn.com/blob/c625613c07118f48908d08ec3c5f5f9a9f813850_40.png?074020d"
width="40" height="40"></noscript></a></div>
<div class="info">
<h2 class="n">2. <a class="business-name" href="/milwaukee-wi/mip/7-eleven-471900245?lid=471900245"
data-analytics="{"target":"name","feature_click":""}" rel=""
data-impressed="1"><span>7-Eleven</span></a></h2>
<div class="info-section info-primary">
<div class="ratings" data-israteable="true"></div>
<p class="adr"><span class="street-address">1624 W Wells St</span><span class="locality">Milwaukee, </span><span>WI</span> <span>53233</span></p>
<div class="phones phone primary">(414) 342-9710</div>
</div>
<div class="info-section info-secondary">
<div class="categories"><a href="/wi/convenience-stores" data-analytics="{"click_id":1171,"adclick":false,"listing_features":"category","events":""}"
data-impressed="1">Convenience Stores</a></div>
<div class="links"><a class="track-visit-website" href="https://www.7-eleven.com/locations/wi/milwaukee/1624-w-wells-st-35836?yext=35836"
rel="nofollow" target="_blank" data-analytics="{"click_id":6,"act":2,"dku":"https://www.7-eleven.com/locations/wi/milwaukee/1624-w-wells-st-35836?yext=35836","FL":"url","target":"website","LOC":"https://www.7-eleven.com/locations/wi/milwaukee/1624-w-wells-st-35836?yext=35836","adclick":true}"
data-impressed="1">Website</a></div>
</div>
<div class="preferred-listing-features"></div>
<div class="snippet">
<p class="body"><span>From Business: At 7-Eleven, our doors are always open, and our friendly store teams
are ready to serve you. Our fresh, fast and convenient hot foods appeal to any craving, so yo…</span></p>
</div>
</div>
</div>
例如,对于地址,而不是itemprop=address
您需要.street-address
的,等等。
CSS
对于 Locality 的嵌套示例,使用模仿样式选择器的内置选择器。
try:
locality = item.select(".street-address")[0]
addressLocality = locality.text
state_zip = locality.findChildren("span") # returns a list
state = state_zip[0]
zip = state_zip[1]
# Might want to add some checks if the state or zip is missing, etc.
except Exception:
addressLocality = ""
总之:
修复那些硬编码的值以匹配新的类名,你应该重新开始工作。