问题描述
如何修改脚本,以便仅打印品牌和partno?在这种情况下,第一行的品牌是CENTRIC,而partno是30016020。我已经在响应文件中包含了前两行。
from bs4 import BeautifulSoup
import requests
url = "https://www.rockauto.com/en/catalog/ford,2015,f-150,3.5l+v6+turbocharged,3308773,brake+&+wheel+hub,brake+pad,1684"
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data,'html.parser')
line = soup.find_all('div',class_='listing-text-row-moreinfo-truck')
print(line)
追踪
[<div class="listing-text-row-moreinfo-truck"><span class="listing-final-manufacturer">CENTRIC</span> <span alt="Buyer's Guide" class="listing-final-partnumber as-link-if-js buyers-guide-color" id="vew_partnumber[8]" onclick='if (cataloglite.IsMobileAndNotExpanded("8")) { return; } cataloglite.ShowBuyersGuidePopup("8");' title="Buyer's Guide">30016020</span> <span class="span-link-underline-remover">Semi-Metallic; w/Shims and Hardware</span> <a class="ra-btn ra-btn-moreinfo" href="https://www.rockauto.com/en/moreinfo.PHP?pk=6113958&cc=3308773" onclick='this.href += "&jsn=8"; AddSerializedCookieDataToHref(this);' rel="opener" target="_blank">Info</a> <span class="truck ra-hide remove-for-print mouSEOver" name="vew_whtruckicon[8][0-0-0-1]" onclick="FAQpopup('/help/?page=2#MINSHIPCOST',"Could ship from same location as parts in cart",null,this); RA.StopBubble(event); return false;" title="Could ship from same location as parts in cart"></span> </div>,<div class="listing-text-row-moreinfo-truck"><span class="listing-final-manufacturer">CENTRIC</span> <span alt="Buyer's Guide" class="listing-final-partnumber as-link-if-js buyers-guide-color" id="vew_partnumber[9]" onclick='if (cataloglite.IsMobileAndNotExpanded("9")) { return; } cataloglite.ShowBuyersGuidePopup("9");' title="Buyer's Guide">30116020</span> <span class="span-link-underline-remover">Ceramic; w/Shims and Hardware</span> <a class="ra-btn ra-btn-moreinfo" href="https://www.rockauto.com/en/moreinfo.PHP?pk=8839680&cc=3308773" onclick='this.href += "&jsn=9"; AddSerializedCookieDataToHref(this);' rel="opener" target="_blank">Info</a> <span class="truck ra-hide remove-for-print mouSEOver" name="vew_whtruckicon[9][0-0-0-1]" onclick="FAQpopup('/help/?page=2#MINSHIPCOST',this); RA.StopBubble(event); return false;" title="Could ship from same location as parts in cart">
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)