【发布时间】:2020-09-30 17:43:02
【问题描述】:
this_page = read_html("https://apu.edu/athletics")
> this_page
{xml_document}
<html id="ctl00_html" lang="en" class=" index homepage">
[1] <head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<script>window.client_hostname = "athletics.apu.edu";window.server_name = "79077 ...
[2] <body>\n<div style="position: fixed; left: -10000px"><script src="//cdn.blueconic.net/azusa.js" async=""></script></div>\n<script>(function(i,s,o,g,r,a,m){i[ ...
虽然我们读取了https://apu.edu/athletics,但它重定向到athletics.apu.edu。在浏览器中都是如此,也可以在this_page 的输出中看到:<script>window.client_hostname = "athletics.apu.edu"; ...
是否可以从this_page 变量中提取此值?
编辑:目前排名前 3 的答案(ekoam、David、Allan)都有效,并且都需要相同的时间(0.35 秒)。我接受了trace_redirects 的答案,因为它提供了所有重定向的附加信息...
【问题讨论】:
-
不确定
rvest是否可以做到这一点。应该可以使用selenium,入门请参阅this。 -
为什么不只是
read_html("https://athletics.apu.edu")? -
@ekoam 我收到了一长串 URL。提供了
apu.edu/athletics,但没有提供athletics.apu.edu。
标签: r web-scraping rvest xml2