Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX]: Webtool optional headers #1229

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jaseci_core/jaseci/extens/act_lib/tests/fixtures/webtool.jac
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ walker get_meta_valid {
}

walker get_meta_need_auth {
has url = "https://docs.google.com/presentation/d/1lIYEuzzhZZ9PJaG_u3XgrFXX5Y6xd0zHV-aB2F8bXXU/edit";
has url = "https://github.com/settings/profile";
can webtool.get_page_meta;
report webtool.get_page_meta(url);
}
Expand All @@ -26,5 +26,7 @@ walker get_meta_timeout {
walker get_meta_need_header {
has url = "https://www.invaluable.com/blog/what-is-a-mandala/";
can webtool.get_page_meta;
report webtool.get_page_meta(url);
report webtool.get_page_meta(url, headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"
});
}
6 changes: 2 additions & 4 deletions jaseci_core/jaseci/extens/act_lib/webtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@jaseci_action()
def get_page_meta(url: str, timeout: int = 3, parser: str = "lxml"):
def get_page_meta(url: str, timeout: int = 3, parser: str = "lxml", headers: dict = {}):
"""
Util to parse metadata out of urls and html documents
Parser option: lxml (default), html5lib, html.parser
Expand All @@ -15,9 +15,7 @@ def get_page_meta(url: str, timeout: int = 3, parser: str = "lxml"):
webpage = requests.get(
url,
timeout=timeout,
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"
},
headers=headers,
)
soup = BeautifulSoup(webpage.content, features=parser)
meta = soup.find_all("meta")
Expand Down
Loading