Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

r - Scraping a website with rvest: "Current page doesn't appear to be html."

I try to access this website: https://www.apa.org/pubs/journals/browse?query=Title:*&type=journal

However, I get the error message: Current page doesn't appear to be html.

I thus cannot proceed to scrape the website with html_nodes etc.

This is my code:

apa_url <- "https://www.apa.org/pubs/journals/browse?query=Title:*&type=journal"

apa_page <- rvest::html_session(apa_url,
                                httr::user_agent("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.20 (KHTML, like Gecko) Chrome/11.0.672.2 Safari/534.20"))

If you know how to fix it, I would be grateful for your help!

question from:https://stackoverflow.com/questions/65559834/scraping-a-website-with-rvest-current-page-doesnt-appear-to-be-html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You haven't shared what you want to scrape but you don't need to create a session.

For example, to get titles of the journal in the first page you can do :

library(rvest)
apa_url <- "https://www.apa.org/pubs/journals/browse?query=Title:*&type=journal"

apa_url %>%
  read_html() %>%
  html_nodes('section.sresults li a') %>%
  html_text()

# [1] "American Journal of Orthopsychiatry - APA Publishing | APA"               
# [2] "American Psychologist Journal - APA Publishing | APA"                     
# [3] "Archives of Scientific Psychology"                                     
# [4] "Asian American Journal of Psychology"                                     
# [5] "Behavior Analysis: Research and Practice"                          
# [6] "Behavioral Development"       
#...
#...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...