前段時間,有人問我關於淘寶app直播頻道寶貝如何採集?我嘗試了下能夠獲取的到,模擬器登陸不了淘寶,這裏有一個坑就是,模擬器有時候會跳到登陸頁面,登陸不了淘寶;node
1、用Android的SDK目錄下自帶的uiautomatorviewer工具,能夠獲取到app當前界面源代碼,拿其中一部分代碼來分析下:android
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<node index="0" text="" resource-id="com.miui.home:id/force_touch_layer" class="android.widget.FrameLayout" package="com.miui.home" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1920]">web
.........................................................
</xml>app
屬性分析:工具
index 索引post
text 文本內容ui
content-desc 文本描述spa
resource-id 控件的id3d
class 控件的類名xml
package 包名
checkable 是否可選中
checked 是否選中
clickable 是否可點擊
enabled 是否可用
focusable 是否可設置焦點
focused 是否焦點
scrollable 是否可滾動
long-clickable 是否可長按
password 是否密碼類型
selected 是否選中
bounds 矩形區域
經過text或者content-desc能夠獲得app中顯示的文字內容!
2、下面是採集的數據截圖:
第一步:打開淘寶app,找到中間位置 淘寶直播,獲取分類的數據
第二步:獲取淘寶直播ID暱稱
第三步:獲取直播在售的寶貝數據
3、將手機app的界面截圖顯示在桌面,主要就是用GDI繪圖!
關鍵代碼:
Procedure DoPaintImg(DC: HDC; pic : string;h,w:Integer);
var
graphics : TGPGraphics;
Image: TGPImage;
destinationPoints : array[0..2] of TGPPoint ;
begin
destinationPoints[0].X := 0;
destinationPoints[0].Y := 0;
destinationPoints[1].X := h;
destinationPoints[1].Y := 0;
destinationPoints[2].X := 0;
destinationPoints[2].Y := w;
graphics := TGPGraphics.Create(DC);
Image:= TGPImage.Create(pic);
graphics.DrawImage(image, PGPPoint(@destinationPoints), 3);
Image.Free;
graphics.Free;
end;