【问题标题】:Java JSoup scrape of an img src from a website returns a weird urlJava JSoup 从网站抓取 img src 返回一个奇怪的 url
【发布时间】:2020-12-09 21:16:32
【问题描述】:

当我尝试抓取时: https://www.game.co.uk/webapp/wcs/stores/servlet/AjaxCatalogSearchView?searchTermScope=&searchType=&filterTerm=&catGroupId=&maxPrice=&contentOnly=&filterTermOperator=&RASchemaType=&attributeName1=Genre&sType=SimpleSearch&filterType=&resultCatEntryType=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");

【问题讨论】:

    标签: java image web-scraping jsoup src


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    • 还是和以前一样的回报:(
    • ok 这么长时间后不得不编程 java :) 你正在寻找的是“data-src”属性......唯一缺少的是前面的协议:String imageUrl = img.attr("data-src");
    • 你有机会尝试“data-src”吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多