Lấy dữ liệu web nhiều trang về file Excel bằng Power Query (4 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

ptm0412

Bad Excel Member
Thành viên BQT
Administrator
Tham gia
4/11/07
Bài viết
14,632
Được thích
37,319
Donate (Momo)
Donate
Giới tính
Nam
Nghề nghiệp
Consultant
Lấy dữ liệu nhiều trang từ web
Trang web https://www.cophieu68.vn/companylist.php?currentPage=1&o=s&ud=a với số 1 là số thứ tự trang muốn lấy.
Code lấy 20 trang từ 1 đến 20 như sau:

PHP:
let
    InitialWeb = "https://www.cophieu68.vn/companylist.php?currentPage=",
    EndWeb = "&o=s&ud=a",
    Pages = {1..20},
    Source = List.Transform(Pages, (p)=>
    let
        Source0 = Web.Page(Web.Contents(InitialWeb & Text.From(p) & EndWeb)){0}[Data]
    in Source0),
    ColumnList = Table.ColumnNames(Source{0}),
    Source1= Table.FromList(Source,Splitter.SplitByNothing()),
    Result =Table.ExpandTableColumn(Source1,"Column1",ColumnList)
in
    Result
 
Lần chỉnh sửa cuối:
Lấy dữ liệu nhiều trang từ web
Trang web https://www.cophieu68.vn/companylist.php?currentPage=1&o=s&ud=a với số 1 là số thứ tự trang muốn lấy.
Code lấy 20 trang từ 1 đến 20 như sau:

PHP:
let
    InitialWeb = "https://www.cophieu68.vn/companylist.php?currentPage=",
    EndWeb = "&o=s&ud=a",
    Pages = {1..20},
    Source = List.Transform(Pages, (p)=>
    let
        Source0 = Web.Page(Web.Contents(InitialWeb & Text.From(p) & EndWeb)){0}[Data]
    in Source0),
    ColumnList = Table.ColumnNames(Source{0}),
    Source1= Table.FromList(Source,Splitter.SplitByNothing()),
    Result =Table.ExpandTableColumn(Source1,"Column1",ColumnList)
in
    Result
M code này rất tuyệt vời đó ạ.
Nhiều web có các page chạy kiểu này đều có thể ứng dụng để lấy dữ liệu.

TB: sao không tạo topic mới sư phụ? Sẽ có nhiều web cần lấy mà không chạy kiểu này.
 
M code này rất tuyệt vời đó ạ.
Nhiều web có các page chạy kiểu này đều có thể ứng dụng để lấy dữ liệu.
Đây là kiểu lấy dữ liệu kiểu nối chuỗi thành địa chỉ.
Cũng nhiều web chạy kiểu theo ngày, hoặc theo page, trong địa chỉ có thông số ngày hoặc page thì mới lấy được kiểu nối chuỗi thế này.
Một số trang giấu data chỗ khác phải dùng tool các kiểu mới ra.
 
Lấy dữ liệu nhiều trang từ web
Trang web https://www.cophieu68.vn/companylist.php?currentPage=1&o=s&ud=a với số 1 là số thứ tự trang muốn lấy.
Code lấy 20 trang từ 1 đến 20 như sau:

PHP:
let
    InitialWeb = "https://www.cophieu68.vn/companylist.php?currentPage=",
    EndWeb = "&o=s&ud=a",
    Pages = {1..20},
    Source = List.Transform(Pages, (p)=>
    let
        Source0 = Web.Page(Web.Contents(InitialWeb & Text.From(p) & EndWeb)){0}[Data]
    in Source0),
    ColumnList = Table.ColumnNames(Source{0}),
    Source1= Table.FromList(Source,Splitter.SplitByNothing()),
    Result =Table.ExpandTableColumn(Source1,"Column1",ColumnList)
in
    Result

Nhờ thầy và các anh chị hướng dẫn code xử lý lấy dữ liệu link dạng

Em cảm ơn mọi người!
 
Nhờ thầy và các anh chị hướng dẫn code xử lý lấy dữ liệu link dạng
Lấy kiểu vòng lặp nối địa chỉ với số trang (chọn trang tùy ý ở C2 và C3)

PHP:
let
    WStartPage = Excel.CurrentWorkbook(){[Name = "WPages"]}[Content][Column1]{0},
    WEndPage = Excel.CurrentWorkbook(){[Name = "WPages"]}[Content][Column1]{1},
    InitialWPage = "https://luatvietnam.vn/thue-phi-le-phi-4-f6.html?page=",
    PageList = {WStartPage..WEndPage},
    Source = List.Transform(PageList, (p) =>
    let
        Source1 = Web.BrowserContents(InitialWPage & Text.From(p)),
        GetTable = Html.Table(Source1, {{"Column1", ".doc-number"}, {"Column2", ".doc-title *"},
        {"Column3", ".doc-dmy:nth-child(1) .w-doc-dmy2"}, {"Column4", ".m-hide:nth-child(4) .w-doc-dmy2"}},
        [RowSelector=".doc-article"])
    in GetTable),
    GetData = Table.Combine(Source),
    Rename = Table.RenameColumns(GetData,{{"Column1", "STT"}, {"Column2", "Tên"}, {"Column3", "Ngày ban hành"}, {"Column4", "Ngày cập nhật"}})
in
    Rename

1738773801895.png
 

File đính kèm

Lần chỉnh sửa cuối:
Web KT

Bài viết mới nhất

Back
Top Bottom