2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【UiPath】Webサイトのデータスクレイピング

2
Last updated at Posted at 2019-07-02

ページ切り替えが非同期の場合

次ページへのリンクを押し、次ページへ切り替わったかどうかはWebページの移動が行われたかで判断しているようなので、非同期通信で一覧の内容だけが変わるような作りになっていると、2ページ目以降のデータが取得できない。

例:楽天証券のスーパースクリーナーの表など

この場合、「次へ」を押して2ページ目以降もスクレイピングする処理は自分で書かなくてはいけない。
実際のフローは以下のような感じ。

ヘッダー行の認識

どうやら<th>タグで無いと、ヘッダー行として認識してくれないらしい。
再びの楽天証券のスーパースクリーナーの場合、ヘッダーに見える部分は<td>タグで作られているため、どうしても1行目をヘッダーとしてくれない。

DataTableの1行目を列名へ置き換える

1行目を列名として認識してくれない場合、コードを駆使して1行目を列名にすると良いかも知れない。
アクティビティを駆使しても良いが、効率が悪いのでコードを呼び出しアクティビティにコードを書いてしまう方が良い。
以下、サンプル。

引数:

名前 IN/OUT
in_dt IN DataTable
out_dt OUT DataTable
コード
If in_dt.Rows.Count = 0 Then
	Exit Sub
End If

Dim firstRow As DataRow = in_dt.Rows(0)

For colIdx As Integer = 0 To in_dt.Columns.Count - 1
	If IsDBNull(firstrow(colidx)) Then
		Continue For
	End If
	Dim columnName As String = CStr(firstRow(colIdx))
	
	If String.IsNullOrWhiteSpace(columnName) Then
		Continue For
	End If
	
	in_dt.Columns(colidx).ColumnName = columnName
Next

in_dt.Rows.Remove(firstRow)
out_dt = in_dt
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?