Skip to content

browser.get.url#

Functions#

current() #

Get URL of the current page, e.g. https://example.com.

Returns:

Type Description
str

URL of the current page, e.g. https://example.com.

Example

This will output the URL https://example.com in the terminal:

1
2
3
4
5
6
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    current_url = browser.get.url.current()
    print(current_url)

current_domain() #

Get domain of the current page, e.g. example.com.

Returns:

Type Description
str

Domain of the current page, e.g. example.com.

Example

This will output the domain example.com in the terminal:

1
2
3
4
5
6
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    current_domain = browser.get.url.current_domain()
    print(current_domain)

from_image(xpath, timeout=None) #

Get the source URL of an <img> image element.

Note

This method targets the src attribute of an <img> image element. And it assumes that the image isn't empty and therefore will retry to get the URL (for better support of single-page apps with extended loading time).

Parameters:

Name Type Description Default
xpath str

XPath of the image. Should target an <img> tag.

required
timeout float | None

In seconds. Timeout to wait for element. If None, the global timeout setting is used (default 5 seconds).

None

Returns:

Type Description
str | None

URL source of the image. If the image does not exist, None is returned.

Example
image_url = browser.get.url.from_image("//xpath/to/img")
print(image_url)

from_images(xpath, timeout=None) #

Get list of source URLs of a group of <img> image elements.

Note

This method targets the src attribute of the <img> image elements. And it assumes that the XPath targets multiple images.

Parameters:

Name Type Description Default
xpath str

XPath of the images. Should target <img> tags.

required
timeout float | None

In seconds. Timeout to wait for element. If None, the global timeout setting is used (default 5 seconds).

None

Returns:

Type Description
list[str | None]

List of image URLs. If an image does not exist, None is added to the list.

Example
1
2
3
image_urls = browser.get.url.from_images("//img")
for image_url in image_urls:
    print(image_url)

Get the source URL of an <a> link element.

Note

This method targets the href attribute of the <a> link element. And it assumes that the link isn't empty and therefore will retry to get the URL (for better support of single-page apps with extended loading time).

Parameters:

Name Type Description Default
xpath str

XPath of the link. Should target an <a> tag.

required
timeout float | None

In seconds. Timeout to wait for element. If None, the global timeout setting is used (default 5 seconds).

None

Returns:

Type Description
str | None

URL of the link. If the link does not exist, None is returned.

Example
link_url = browser.get.url.from_link("//xpath/to/a")
print(link_url)

Get list of source URLs of a group of <a> link elements.

Note

This method targets the href attribute of the <a> link elements. And it assumes that the XPath targets multiple links.

Parameters:

Name Type Description Default
xpath str

XPath of the links. Should target <a> tags.

required
timeout float | None

In seconds. Timeout to wait for element. If None, the global timeout setting is used (default 5 seconds).

None

Returns:

Type Description
list[str | None]

List of link URLs. If a link does not exist, None is added to the list.

Example
1
2
3
link_urls = browser.get.url.from_links("//a")
for link_url in link_urls:
    print(link_url)