Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.9K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

XPath Query: get URL from href attribute.

Posted 3 years ago

I want to extract the URL attribute embedded in the href, as shown below:

enter image description here enter image description here

The second screenshot, which includes the want-to-extract URL indicated by the circle numbered 2, is opened by clicking the button indicated by the circle numbered 1 in the first screenshot.

For this purpose, I tried the following but failed:

In[258]:= session = StartWebSession[]; 
WebExecute["OpenPage" -> "https://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-getgen?list=new&what=gen&gnum=7"]; 
elements = WebExecute["LocateElements" -> "ITA Settings"]; 
WebExecute["ElementAttribute" -> {First@elements, "href"}]


Out[261]= Failure["InvalidInput", <|"MessageTemplate" -> "`command` \
failed.", "MessageParameters" -> <|"command" -> "ElementAttribute"|>, 
  "Element" -> "InvalidInput"|>]

How should I adjust my usage to achieve the goals described here?

Regards,
Zhao

POSTED BY: Hongyi Zhao
5 Replies
Posted 3 years ago
POSTED BY: Hongyi Zhao
Posted 3 years ago
POSTED BY: Hongyi Zhao
POSTED BY: Daniel Lichtblau
Posted 3 years ago

Done! See here.

POSTED BY: Hongyi Zhao
Posted 3 years ago

Hi Hongyi

The circle numbered 1 is not a URL, it is a button in an HTML form (you can see this by using Chrome Developer Tools). You can submit the form for the last form input element which is "ITA Settings" like this

session = StartWebSession[];
page = WebExecute[
  "OpenPage" -> 
   "https://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-getgen?list=new&what=gen&gnum=7"]
inputs = WebExecute[session, "LocateElements" -> "Tag" -> "Input"]
WebExecute[session, "ClickElement" -> Last@inputs]

That will take you to the page with the circle number 2. On that page, each row of the table (apart from the header) does have a link. To navigate to a particular one

anchors = WebExecute["LocateElements" -> "Tag" -> "a"]
pb11 = anchors // 
  Select[StringStartsQ[WebExecute[session, "ElementText" -> #], "P b 1 1"] &]
WebExecute[session, "ClickElement" -> pb11]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard