使用Python我想提取從一堆的包含硬編碼數據JavaScript文件下方到csv文件中所示的數據行,如下所示:變換硬編碼初始化值到CSV
....html code.... hotels[0] = new hotelData(); hotels[0].hotelName = "MANHATTAN"; hotels[0].hotelPhone = ""; hotels[0].hotelSalesPhone = ""; hotels[0].hotelPhone = 'Phone: 888-350-6432
'; hotels[0].hotelStreet = "787 11TH AVENUE"; hotels[0].hotelCity = "NEW YORK"; hotels[0].hotelState = "NY"; hotels[0].hotelZip = "10019"; hotels[0].hotelId = "51543"; hotels[0].hotelLat = "40.7686";; hotels[0].hotelLong = "-73.992645";; hotels[1] = new hotelData(); hotels[1].hotelName = "KOEPPEL"; hotels[1].hotelPhone = ""; hotels[1].hotelSalesPhone = ""; hotels[1].hotelPhone = 'Phone: 718-721-9100
'; hotels[1].hotelStreet = "57-01 NORTHERN BLVD."; hotels[1].hotelCity = "WOODSIDE"; hotels[1].hotelState = "NY"; hotels[1].hotelZip = "11377"; hotels[1].hotelId = "51582"; hotels[1].hotelLat = "40.75362";; hotels[1].hotelLong = "-73.90366";; var mykey = "AlvQ9gNhp7oNuvjhkalD4OWVs_9LvGHg0ZLG9cWwRdAUbsy-ZIW1N9uVSU0V4X-8"; var map = null; var pins = null; var i = null; var boxes = new Array(); var currentBox = null; var mapOptions = { credentials: mykey, enableSearchLogo: false, showMapTypeSelector: false, enableClickableLogo: false } .....html code .....
因此所需的CSV輸出就像上面的數據行一樣:
MANHATTAN,,,Phone: 888-350-6432 ... KOEPPEL,,,Phone: 718-721-9100 ...
我應該使用代碼生成工具直接解析上述語句來獲取數據嗎?將成千上萬個Javascript文件中包含的數據轉換爲csv表格格式的最有效的Python方法是哪一種?
更新:
理想我想解決解析JavaScript語句爲Python對象,然後存儲它以CSV從訂貨和輸入腳本代碼的格式獲得最大的獨立
感謝您的建議,但我想解析這些聲明以獲得最大獨立性,如問題更新中所建議的。 – stackit