כלים ללכידה ולהמרה של האינטרנט

ללכוד טבלאות HTML מאתרי אינטרנט עם רובי

ממשק API של רובי

המרת טבלאות HTML into גיליונות אלקטרוניים של JSON, CSV ו- Excel באמצעות ממשק API רובי של GrabzIt ממזרח פשוט עקוב אחר הדוגמאות המוצגות כאן. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל url_to_table, html_to_table or file_to_table שיטות save or save_to יש לקרוא לשיטה ללכידת הטבלה. אם אתה רוצה לראות במהירות אם שירות זה מתאים לך, אתה יכול לנסות הדגמה חיה של לכידת טבלאות HTML מכתובת אתר.

אפשרויות בסיסיות

הדוגמה הבאה ממירה את טבלת ה- HTML הראשונה בדף אינטרנט שצוין intoa מסמך CSV.

grabzItClient.url_to_table("https://www.tesla.com")
# Then call the save or save_to method
grabzItClient.html_to_table("<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 save_to method
grabzItClient.file_to_table("tables.html")
# Then call the save or save_to method

אם אינך רוצה להמיר אוטומטית את הטבלה הראשונה בדף אינטרנט תוכל לציין את הטבלה tableNumberToInclude שיטה. למשל ציון 2 ימיר את הטבלה השנייה שנמצאת בדף אינטרנט.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.tableNumberToInclude = 2

grabzItClient.url_to_table("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.csv"
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.tableNumberToInclude = 2

grabzItClient.html_to_table("<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 save_to method
grabzItClient.save_to("result.csv")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.tableNumberToInclude = 2

grabzItClient.file_to_table("tables.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.csv")

אתה יכול גם לציין את targetElement שיטה שתבטיח רק טבלאות בתוך מזהה האלמנט שצוין יומרו.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.targetElement = "stocks_table"

grabzItClient.url_to_table("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.csv")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.targetElement = "stocks_table"

grabzItClient.html_to_table("<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 save_to method
grabzItClient.save_to("result.csv")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.targetElement = "stocks_table"

grabzItClient.file_to_table("tables.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.csv")

אם אתה משתמש בפורמט XLSX אתה יכול ללכוד את כל הטבלאות בדף אינטרנט על ידי העברת נאמן ל- includeAllTables שיטה. לאחר מכן זה יכניס כל טבלה לגיליון חדש בתוך חוברת העבודה של הגיליון האלקטרוני.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.format = "xlsx"
options.includeAllTables = true

grabzItClient.url_to_table("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.xlsx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.format = "xlsx"
options.includeAllTables = true

grabzItClient.html_to_table("<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 save_to method
grabzItClient.save_to("result.xlsx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.format = "xlsx"
options.includeAllTables = true

grabzItClient.file_to_table("tables.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.xlsx")

המרת טבלאות HTML ל- JSON

בעזרת GrabzIt, רובי יכול להמיר טבלאות HTML בקלות into JSON לעשות זאת json בפרמטר הפורמט. בדוגמה למטה הנתונים נקראים באופן סינכרוני באמצעות save_to שיטה, להשיג את JSON בתור string. זה יכול להיות מנותח על ידי ספרייה כמו ג'ונסון פנינה.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.format = "json"
options.tableNumberToInclude = 1

grabzItClient.url_to_table("https://www.tesla.com", options)

json = grabzItClient.save_to()
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.format = "json"
options.tableNumberToInclude = 1

grabzItClient.html_to_table("<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)

json = grabzItClient.save_to()
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.format = "json"
options.tableNumberToInclude = 1

grabzItClient.file_to_table("tables.html", options)

json = grabzItClient.save_to()

מזהה מותאם אישית

אתה יכול להעביר מזהה מותאם אישית אל ה- שולחן שיטות כמוצג להלן, ערך זה מוחזר לאחר מכן למטפל GrabzIt Ruby שלך. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך צילום מסך לרשומת מסד נתונים מסוימת.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.customId = "123456"

grabzItClient.url_to_table("https://www.tesla.com", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.customId = "123456"

grabzItClient.html_to_table("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::TableOptions.new()
options.customId = "123456"

grabzItClient.file_to_table("example.html", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")