Java使用JSOUP在Ebay/Amazon上获取产品链接

Java使用JSOUP在Ebay/Amazon上获取产品链接,java,jsoup,Java,Jsoup,我想做一个程序,去易趣,并获得所有的标题,价格和我选择的物品清单链接。例如,我可以查看iPhone11的价格,我的程序应该给我一个按价格顺序排列的所有列表,然后是每个列表旁边的链接。但我似乎无法找到如何获取列表的链接 我的代码: import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import java.util.*; import java.util.stream.C

我想做一个程序,去易趣,并获得所有的标题,价格和我选择的物品清单链接。例如,我可以查看iPhone11的价格,我的程序应该给我一个按价格顺序排列的所有列表,然后是每个列表旁边的链接。但我似乎无法找到如何获取列表的链接

我的代码:

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static int[] addX(int n, int arr[], int x)
    {
        int i;

        // create a new array of size n+1
        int newarr[] = new int[n + 1];

        // insert the elements from
        // the old array into the new array
        // insert all elements till n
        // then insert x at n+1
        for (i = 0; i < n; i++)
            newarr[i] = arr[i];

        newarr[n] = x;

        return newarr;
    }
    public static void main(String[] args) {
        final String url =
                "https://www.ebay.co.uk/sch/i.html?_from=R40&_sacat=0&_nkw=iphone+11&LH_BIN=1&Model=Apple%2520iPhone%252011&_dcat=9355&rt=nc&LH_ItemCondition=3000";
        ArrayList<Integer> itemPrice = new ArrayList<>();
        ArrayList<String> itemTitle = new ArrayList<>();
        ArrayList<String> itemLink = new ArrayList<>();
        try {
            final Document document = Jsoup.connect(url).get();

            for (Element row : document.select("li.s-item--watch-at-corner")) {
                final String itemTitle2 = row.select(".clearfix.s-item__wrapper > .clearfix.s-item__info > .s-item__link > .s-item__title").text();
                final String itemLink2 = 'HELP HERE';
                final String tempItemPrice = row.select("div.s-item__detail--primary.s-item__detail:nth-of-type(1) > .s-item__price").text();
                final String fixTempItemPrice = tempItemPrice.replaceAll("[£ ,]", "");
                double doubleItemPrice = Double.parseDouble(fixTempItemPrice);
                int intItemPrice = (int)doubleItemPrice;
                itemPrice.add(intItemPrice);
                itemTitle.add(itemTitle2);
                itemLink.add(itemLink2);
            }

        }
        catch (Exception ex) {
            ex.printStackTrace();
        }

        Map<String, Integer> map = new HashMap<String, Integer>();
        for (int i = 0; i < itemTitle.size(); i++) map.put(itemTitle.get(i), itemPrice.get(i));
        Map<String, Integer> sortedMap = new LinkedHashMap<>();
        map.entrySet().stream().sorted(Map.Entry.<String, Integer>comparingByValue()).forEachOrdered(e -> sortedMap.put(e.getKey(), e.getValue()));
        for (String key : sortedMap.keySet()) System.out.println("ITEM: " + key + " PRICE: £" + sortedMap.get(key));

        System.out.println(itemLink.get(1));
    }

}
import org.jsoup.jsoup;
导入org.jsoup.nodes.Document;
导入org.jsoup.nodes.Element;
导入java.util.*;
导入java.util.stream.collector;
公共班机{
公共静态int[]addX(int n,int arr[],int x)
{
int i;
//创建大小为n+1的新数组
int newarr[]=新int[n+1];
//从中插入元素
//将旧数组转换为新数组
//插入所有元素,直到n
//然后在n+1处插入x
对于(i=0;i
  • [tridion]相关文章推荐