我很难在其中使用特殊字符跳转到其中。当我键入链接到chrome时它可以工作,但在R / rvest中我收到一个错误:
curl :: curl_fetch_memory(url,handle = handle)出错:
无法解析主持人:NA
有问题的网址:
http://incrediblewinestore.com/ProductDetail.asp?title= - 您-只好-ME-AT-梅洛 - 餐巾&安培; UPCCode = 876718049392
http://incrediblewinestore.com/ProductDetail.asp?title=10-BARREL-RASPBERRY-CRUSH-6PK&UPCCode=`851538002611
http://incrediblewinestore.com/ProductDetail.asp?title=14-HANDS-CABERNET-SAUVIGNON&UPCCode= \ 088586001895
有效的网址:
我试过的代码:
library(stringr)
library(rvest)
# Load first page, try to go to search, but expect age-check
iws_ac_url <- "http://incrediblewinestore.com"
iws_session <- html_session(iws_ac_url)
age_gate <- iws_session %>%
html_node("form[name='AgeGate']")
age_gate <- html_form(age_gate)
age_gate <- set_values(age_gate, PageAction = 'Yes21')
# Submit form and enter the rest of the site
iws_site <- submit_form(iws_session,age_gate)
# Unworking Links
temp_link <- paste0("http://incrediblewinestore.com","/ProductDetail.asp?title=<i>-You-Had-Me-At-Merlot-<i>-Napkins&UPCCode=876718049392")
iws_site %>% jump_to(temp_link)
temp_link <- paste0("http://incrediblewinestore.com","/ProductDetail.asp?title=10-BARREL-RASPBERRY-CRUSH-6PK&UPCCode=`851538002611")
iws_site %>% jump_to(temp_link)
# Working link
temp_link <- paste0("http://incrediblewinestore.com","/ProductDetail.asp?title=Cuarenta-y-Tres-Liqueur-43&UPCCode=029929115411")
iws_site %>% jump_to(temp_link)
答案 0 :(得分:0)
URLencode(url,reserved = FALSE)
temp_link <- paste0("http://incrediblewinestore.com",URLencode("/ProductDetail.asp?title=10-BARREL-RASPBERRY-CRUSH-6PK&UPCCode=`851538002611",reserved = FALSE))
秘密是我需要一个不会编码保留字符的函数,比如=? &安培; 。我尝试的另一个功能是转换所有字符。