એચટીએમએલ કોષ્ટકોને રૂપાંતરિત કરવાની ઘણી રીતો છે intઓ JSON, CSV અને એક્સેલ સ્પ્રેડશીટ્સ નો ઉપયોગ કરીને GrabzIt ની જાવા API, અહીં વિગતવાર કેટલીક સૌથી ઉપયોગી તકનીકો છે. જો કે તમે પ્રારંભ કરતા પહેલા યાદ રાખો કે ફોન કર્યા પછી URLToTable, HTMLToTable or ફાઇલટોટેબલ પદ્ધતિઓ Save or SaveTo ટેબલને કેપ્ચર કરવા માટે પદ્ધતિ કહેવી આવશ્યક છે. જો તમે ઝડપથી જોવા માંગતા હો કે આ સેવા તમારા માટે યોગ્ય છે કે નહીં, તો તમે એક પ્રયાસ કરી શકો છો એચટીએમએલ કોષ્ટકો કબજે લાઇવ ડેમો એક URL માંથી.
આ કોડ સ્નિપેટ નિર્દિષ્ટ વેબપેજ પર મળેલા પ્રથમ HTML ટેબલને કન્વર્ટ કરશે intસીએસવી દસ્તાવેજ.
grabzIt.URLToTable("https://www.tesla.com"); //Then call the Save or SaveTo method
grabzIt.HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr> <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr> </table></body></html>"); //Then call the Save or SaveTo method
grabzIt.FileToTable("tables.html"); //Then call the Save or SaveTo method
ડિફ defaultલ્ટ રૂપે આ તે ઓળખાતા પહેલા કોષ્ટકમાં રૂપાંતરિત થશે intઓએ ટેબલ. જો કે વેબ પૃષ્ઠમાંનો બીજો કોષ્ટક એક 2 પસાર કરીને રૂપાંતરિત કરી શકાય છે setTableNumberToInclude ની પદ્ધતિ TableOptions વર્ગ.
setTableNumberToInclude
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setTableNumberToInclude(2); grabzIt.URLToTable("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.csv");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setTableNumberToInclude(2); grabzIt.HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr> <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr> </table></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.csv");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setTableNumberToInclude(2); grabzIt.FileToTable("tables.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.csv");
તમે પણ ઉપયોગ કરી શકો છો setTargetElement પદ્ધતિ એ સુનિશ્ચિત કરવા માટે કે ફક્ત ઉલ્લેખિત તત્વ ID ની અંદરના કોષ્ટકોને રૂપાંતરિત કરવામાં આવશે.
setTargetElement
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setTargetElement("stocks_table"); grabzIt.URLToTable("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.csv");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setTargetElement("stocks_table"); grabzIt.HTMLToTable("<html><body><table id='stocks_table'><tr><th>Name</th><th>Age</th></tr> <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr> </table></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.csv");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setTargetElement("stocks_table"); grabzIt.FileToTable("tables.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.csv");
વૈકલ્પિક રૂપે તમે વેબ પેજ પરનાં બધા કોષ્ટકોને કેપ્ચર કરી શકો છો setIncludeAllTables પદ્ધતિ, જો કે આ ફક્ત XLSX અને JSON ફોર્મેટ્સ સાથે કાર્ય કરશે. આ વિકલ્પ જનરેટ કરેલી સ્પ્રેડશીટ વર્કબુકમાં દરેક કોષ્ટકને નવી શીટમાં મૂકશે.
setIncludeAllTables
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setFormat(TableFormat.XLSX); options.setIncludeAllTables(true); grabzIt.URLToTable("https://www.tesla.com", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.xlsx");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setFormat(TableFormat.XLSX); options.setIncludeAllTables(true); grabzIt.HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr> <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr> </table></body></html>", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.xlsx");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setFormat(TableFormat.XLSX); options.setIncludeAllTables(true); grabzIt.FileToTable("tables.html", options); //Then call the Save or SaveTo method grabzIt.SaveTo("result.xlsx");
GrabzIt વેબ પર મળેલા HTML કોષ્ટકોને JSON માં કન્વર્ટ પણ કરી શકે છે, તેના બદલે ફક્ત JSON ફોર્મેટનો ઉલ્લેખ કરો. નીચેના ઉદાહરણમાં ડેટા એક સાથે સુમેળમાં વાંચવામાં આવે છે અને એ તરીકે પરત આવે છે GrabzItFile નો ઉપયોગ કરીને objectબ્જેક્ટ SaveTo પદ્ધતિ, જો કે સામાન્ય રીતે ભલામણ કરવામાં આવે છે કે તમે આ કરો અસુમેળ.
GrabzItFile
SaveTo
જ્યારે રૂપાંતર પૂર્ણ થાય છે toString એક તરીકે JSON મેળવવા માટે પદ્ધતિ કહેવામાં આવે છે string, આ પછી જેવા લાઇબ્રેરી દ્વારા વિશ્લેષણ કરી શકાય છે ગૂગલ જીસન.
toString
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setFormat(TableFormat.JSON); options.setTableNumberToInclude(1); grabzIt.URLToTable("https://www.tesla.com", options); GrabzItFile file = grabzIt.SaveTo(); if (file != null) { String json = file.toString(); }
તમે કસ્ટમ ઓળખાણકર્તાને પાસ કરી શકો છો ટેબલ નીચે બતાવેલ પદ્ધતિઓ, આ મૂલ્ય પછી તમારા GrabzIt જાવા હેન્ડલર પર પાછા ફર્યા છે. હમણાં પૂરતું આ કસ્ટમ આઇડેન્ટિફાયર ડેટાબેસ ઓળખકર્તા હોઈ શકે છે, સ્ક્રીનશ .ટને ચોક્કસ ડેટાબેઝ રેકોર્ડ સાથે જોડવાની મંજૂરી આપે છે.
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setCustomId("123456"); grabzIt.URLToTable("https://www.tesla.com", options); //Then call the Save method grabzIt.Save("http://www.example.com/handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setCustomId("123456"); grabzIt.HTMLToTable("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the Save method grabzIt.Save("http://www.example.com/handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); TableOptions options = new TableOptions(); options.setCustomId("123456"); grabzIt.FileToTable("example.html", options); //Then call the Save method grabzIt.Save("http://www.example.com/handler");