繁体   English   中英

Java JSoup 从网站抓取 img src 返回一个奇怪的 url

[英]Java JSoup scrape of an img src from a website returns a weird url

当我尝试抓取: https://www.game.co.uk/webapp/wcs/stores/servlet/AjaxCatalogSearchView?searchTermScope=&searchType=&filterTerm=&catGroupId=&maxPrice=&contentOnly=&filterTermOperator=&RASchemaType=&attributeName1=Genre&sType=&resEntryType= =2&catalogId=10201&pageView=image&sortBy=MOST_POPULAR_DESC&minPrice=&categoryType=&attributeValue1=4294952868&storeId=10151&langId=44&catgrpSchemaType=&storeOnly=&searchTerm=rpg&searchTermOperator=&pageNumber=1&inStockOnly=true&pageSize=96

对于一个 img 我得到这个作为回报:

/wcsstore/SafeStorefrontAssetStore/locale/en_GB/Style1/img/email/spacer.gif

我尝试使用.attr("abs:src") 和.attr("src") 但都返回错误的网址。

Elements prods = doc.select(".product");
Elements img = prods.get(i).select(".productHeader a img");
String imageUrl = img.attr("src");

我认为你的问题是你的选择器:

元素 img = prods.get(i).select(".productHeader >a>img ");

那应该可以解决您的问题!

新条目:对于前面没有协议的图像,您需要检查具有 url 的“data-src” String imageUrl = img.attr("data-src");

=> 例如“//img.game.co.uk/ml2/7/3/1/5/731542_ps4_b.png”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM