teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

arender()のwait, sleepパラメータとr.html.page.screenshot.__doc__について追記

2021/11/19 06:50

投稿

lis
lis

スコア15

title CHANGED
File without changes
body CHANGED
@@ -23,8 +23,10 @@
23
23
 
24
24
  またPCのChromeからUser-Agent偽装してアクセスし、正常に表示されることを確認したUser-Agentを用いて実施しても、同様の状況となっております。
25
25
 
26
- ### 試したことと保存された画像の状況
26
+ ## 試したこと
27
27
 
28
+ ### arender()のkeep_page, reloadパラメータに応じた保存画像の状況
29
+
28
30
  ・`r.html.arender()`の`keep_page`, `reload`の値を変更することで状況が変わった。
29
31
 
30
32
  - keep_page=False: r.html.page=Noneとなり`r.html.page.screenshot()`でエラー(このためTrueに固定)
@@ -32,6 +34,48 @@
32
34
  - reload=False: r.html.arender()が実行された後、スマホ用サイトが読み込まれるが、スマホ用ページだが画像やスタイルなど適用されていないようなものが保存される(表示画面とは異なる状態)
33
35
  →例えば背景が黒なのに白い、ハンバーガーメニューで畳まれているメニューがリスト表示されている等
34
36
 
37
+ ### arender()のwait, sleepパラメータを設定
38
+
39
+ arender()にwait, sleepパラメータを設定(長めにしてみた)。
40
+
41
+ 結果は変わらず期待した画像の取得はできなかった。
42
+
43
+ ```python
44
+ await r.html.arender(wait=60, sleep=60, keep_page=True, reload=False)
45
+ ```
46
+
47
+ ### r.html.page.screenshot.__doc__を確認
48
+
49
+ print(r.html.page.screenshot.__doc__)を出力してみたが、画像ファイル形式に関するものしかなかったため、今回の期待値へのアプローチとは関係ない模様。
50
+
51
+ ```
52
+ # print(r.html.page.screenshot.__doc__)
53
+ Take a screen shot.
54
+
55
+ The following options are available:
56
+
57
+ * ``path`` (str): The file path to save the image to. The screenshot
58
+ type will be inferred from the file extension.
59
+ * ``type`` (str): Specify screenshot type, can be either ``jpeg`` or
60
+ ``png``. Defaults to ``png``.
61
+ * ``quality`` (int): The quality of the image, between 0-100. Not
62
+ applicable to ``png`` image.
63
+ * ``fullPage`` (bool): When true, take a screenshot of the full
64
+ scrollable page. Defaults to ``False``.
65
+ * ``clip`` (dict): An object which specifies clipping region of the
66
+ page. This option should have the following fields:
67
+
68
+ * ``x`` (int): x-coordinate of top-left corner of clip area.
69
+ * ``y`` (int): y-coordinate of top-left corner of clip area.
70
+ * ``width`` (int): width of clipping area.
71
+ * ``height`` (int): height of clipping area.
72
+
73
+ * ``omitBackground`` (bool): Hide default white background and allow
74
+ capturing screenshot with transparency.
75
+ * ``encoding`` (str): The encoding of the image, can be either
76
+ ``'base64'`` or ``'binary'``. Defaults to ``'binary'``.
77
+ ```
78
+
35
79
  ## ソース
36
80
 
37
81
  [参考ページ](https://qiita.com/uitspitss/items/f131ea79dffd58bc01ae)を元にスクリーンショット用のメソッドを作成しました。
@@ -62,4 +106,4 @@
62
106
 
63
107
  ## 参考ページ
64
108
 
65
- - https://qiita.com/uitspitss/items/f131ea79dffd58bc01ae
109
+ - [https://qiita.com/uitspitss/items/f131ea79dffd58bc01ae](https://qiita.com/uitspitss/items/f131ea79dffd58bc01ae)

1

表示が異なる箇所と環境差異に対することを追記(見出し追加)、試したことを見出しとして区切った。

2021/11/19 06:50

投稿

lis
lis

スコア15

title CHANGED
File without changes
body CHANGED
@@ -10,8 +10,21 @@
10
10
 
11
11
  しかし保存された画像は、実際にスマホで表示した画面とは異なるものでした。
12
12
 
13
- 下記、試したことと保存された画像の状況とります。
13
+ ### 表示が異る箇所の例
14
14
 
15
+ - 本来設定されている背景色が設定がない(白背景)
16
+ - トップ画像などすべての画像が表示されていない
17
+ - ハンバーガーメニューに畳まれるはずのメニューが`<ul><li>`をそのままリスト表示した状態で表示されている
18
+
19
+ これらのことから恐らくそもそもCSSが適用されていない状態と思われます。
20
+
21
+ 実施したスマホ用ページはブラウザサイズをどれだけ大きくしても、表示横幅が広がっていくだけでコンテンツの表示に変更はないページです。
22
+ そのためサイズによる表示の違いは関係ありません。
23
+
24
+ またPCのChromeからUser-Agent偽装してアクセスし、正常に表示されることを確認したUser-Agentを用いて実施しても、同様の状況となっております。
25
+
26
+ ### 試したことと保存された画像の状況
27
+
15
28
  ・`r.html.arender()`の`keep_page`, `reload`の値を変更することで状況が変わった。
16
29
 
17
30
  - keep_page=False: r.html.page=Noneとなり`r.html.page.screenshot()`でエラー(このためTrueに固定)