正如标题所说,我有数字站点ID,我需要一种方法来获得相应的GlobalId。
我知道有匹配的表格
https://developer.ebay.com/DevZone/merchandising/docs/CallRef/Enums/GlobalIdList.html
https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html
但我需要一种编程方式来实现它。
答案 0 :(得分:1)
您的三个选择:
哈希地图实施
import java.util.HashMap;
public class Mappings{
public static void main(String []args){
HashMap myMap = new HashMap<Integer, String>();
myMap.put(0, "EBAY-US");
myMap.put(2, "EBAY-ENCA");
myMap.put(3, "EBAY-GB");
myMap.put(15, "EBAY-AU");
//...
System.out.println("Given ID 15, it's corresponding Global ID is: " + myMap.get(15));
}
}
SQL表实现
//STEP 1. Import required packages
import java.sql.*;
public class JDBCExample {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//STEP 3: Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
//STEP 4: Execute a query
System.out.println("Inserting records into the table...");
stmt = conn.createStatement();
String sql = "INSERT INTO Mappings " +
"VALUES (0, 'EBAY-US')";
stmt.executeUpdate(sql);
sql = "INSERT INTO Mappings " +
"VALUES (2, 'EBAY-ENCA')";
stmt.executeUpdate(sql);
sql = "INSERT INTO Mappings " +
"VALUES (3, 'EBAY-GB')";
stmt.executeUpdate(sql);
sql = "INSERT INTO Mappings " +
"VALUES (15, 'EBAY-AU')";
stmt.executeUpdate(sql);
System.out.println("Inserted records into the table...");
sql = "SELECT siteID, globalID FROM Mappings";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int siteId = rs.getInt("siteID");
int globalId = rs.getInt("globalID");
//Display values
System.out.print("siteId: " + siteId);
System.out.print(", globalId: " + globalId);
}
rs.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}// do nothing
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end JDBCExample
和服实施
如果您不想拥有网站ID的本地存储空间&lt; =&gt;全球ID映射,如techcrunch文章中所述,&#34; Kimono Is A Smarter Web Scraper That Lets You “API-ify” The Web, No Code Required,&#34;:
With Kimono, the end goal is to simplify data extraction so that anyone can manage it.
Then Kimono’s learning algorithm will build a data model involving the items you’ve
selected.
正如Kimono的website所提到的那样:
Turn websites into structured APIs from your browser in seconds.