Block reference / Web interaction

Get page source

Read the page's HTML, inline scripts included, or one value out of it with a regular expression.

Only inWarpX Browser

Get page source returns the HTML of the page the run is on, as it is now, including the <script> tags in it. That is where sites keep values a request needs that nothing on screen shows, such as Facebook's fb_dtsg token or USER_ID. Get text reads only what is rendered. With a regular expression, the block returns just the value its group captures, ready to use in a Page request.

The Get page source block's settings, filled in as in the example below.

Settings

Description

A note shown under the block's name on the canvas. It has no effect on the run.

ExampleRead the user id
Regular expression (optional)

A pattern to find in the HTML, written without the surrounding slashes. Leave it empty to get the whole page. References are filled in first.

Example"USER_ID":"(\d+)"
Groupwhen Regular expression is set

Which capture group to keep: its number, or the name of a named group such as id for (?<id>\d+). Empty is 1. An expression with no groups keeps the whole match.

Example1
Flagswhen Regular expression is set

Any of i (ignore case), s (a dot also matches a line break), m (^ and $ match at each line) and u (Unicode). Other letters are ignored.

Examples
Every match (a list)when Regular expression is set

Returns the group from every match, as a list, instead of from the first only.

ExampleUnchecked
Assign to variable

Stores the result in a variable. On by default.

ExampleChecked
Variable namewhen Assign to variable is on

The variable to store it in. Read it later as {{variables.userId}}.

ExampleuserId
Insert to tablewhen the workflow has table columns

Writes the result to a table column. A list from Every match becomes one row per item, unless the column's type is array. It only appears when the workflow's table has columns.

ExampleUnchecked
Select columnwhen Insert to table is on

The column to write to.

ExampleuserId

Every block also has the shared block settings — a description, Disable block and what to do on an error. Fields that take text accept data from earlier blocks.

What it hands on

The page's HTML, the captured value, or with Every match a list of values. It goes to the variable and the column you ticked. The block leaves by its single output; if the expression matches nothing, it fails.

Example: Read the values a Facebook request needs

  1. Start
  2. Open URL
  3. Get page source
  4. Get page source
  5. Page request
Where Get page source sits in the example workflow.
  1. Add an Open URL block with https://www.facebook.com/ on a profile that is signed in.
  2. Add a Get page source block. Set Regular expression (optional) to "DTSGInitialData",\[\],\{"token":"([^"]+)", leave Group at 1, and tick Assign to variable with the name fb_dtsg.
  3. Add a second Get page source block with "USER_ID":"(\d+)", assigned to userId.
  4. Add a Page request block that sends fb_dtsg={{variables.fb_dtsg}}&av={{variables.userId}} with its form body.

Good to know

  • Nothing matching fails the block with "Nothing on the page matched the expression", rather than leaving an empty variable for a later step to trip on. Use the block's error settings to carry on, for example when the account is signed out.
  • An expression that is not valid fails the block with "The expression is not valid" and the reason.
  • The HTML is the page as it is when the block runs, after its scripts have changed it, not the file the server first sent.
  • After Switch frame into an iframe, the block reads that frame's HTML.
  • The whole page can be large. Keep it in a variable only when you need it; to pull one value out, give the block an expression, or use RegEx variable on the stored HTML.

See also

  • Page request — Send an HTTP request from the open tab, with the page's cookies, and store the answer.
  • Get text — Read the text of one element or many, and save it to the table or a variable.
  • RegEx variable — Replace a text variable with what a regular expression matches, or with a replaced version.
  • JavaScript code — Run your own JavaScript in the page, and pass data back to the workflow.