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

rvest xpath must start with a single quote followed by double quoting any internal strings else does not work #435

Open
SugarRayLua opened this issue Dec 10, 2024 · 0 comments

Comments

@SugarRayLua
Copy link

CCing issue above issue discovered from posting to stack overflow:

https://stackoverflow.com/questions/79267016/how-to-properly-perform-an-xpath-english-text-search-with-r-package-rvest-doesn/79268974#79268974

library(rvest)
library(dplyr)

test <- read_html_live("https://www.cdc.gov")

# single-quotes in xpath, no match:
html_elements(test, xpath = "//a[contains(text(),'Outbreaks')]")
#> {xml_nodeset (0)}

# swap quotes, " <-> '
html_elements(test, xpath = '//a[contains(text(), "Outbreaks")]')
#> {xml_nodeset (3)}
#> [1] <a href="https://www.cdc.gov/outbreaks/index.html">Outbreaks</a>
#> [2] <a href="https://www.cdc.gov/outbreaks/index.html" class="btn btn-outline ...
#> [3] <a href="https://www.cdc.gov/outbreaks/index.html" class="btn btn-outline ...

Perhaps a note about the needed single quotation starting order to an xpath could be added to the rvest documentation
Fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant