Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何提取<;b>;使用rvest从div中标记?_Html_R_Xpath_Web Scraping_Rvest - Fatal编程技术网

Html 如何提取<;b>;使用rvest从div中标记?

Html 如何提取<;b>;使用rvest从div中标记?,html,r,xpath,web-scraping,rvest,Html,R,Xpath,Web Scraping,Rvest,我有这个html: <div class="monty">album: <b>And Now For Something Completely Different</b> (1998)</div> 专辑:现在是完全不同的(1998) 我目前正在使用此xpath查找它: for_monty <- rvest::html_node(for_html_code, xpath = "/html/body/di

我有这个html:

<div class="monty">album: <b>And Now For Something Completely Different</b> (1998)</div>
专辑:现在是完全不同的(1998) 我目前正在使用此xpath查找它:

    for_monty <- rvest::html_node(for_html_code, xpath = "/html/body/div[2]/div/div[2]/div[11]/div[1]/b")

for_-monty听起来您的xpath应该是
//div[@class='monty']/b

我们可以在您自己的代码片段上作为完整的reprex进行尝试:

库(rvest)
#>正在加载所需的包:xml2
html%
html_节点(xpath=“//div[@class='monty']]/b”)
#>{xml_nodeset(1)}
#>[1]现在,我们来看一个完全不同的例子

由(v0.3.0)于2020年12月14日创建

噢,哇,非常感谢!这很好用。有没有什么地方可以让我读到更多关于这类路径以及如何创建它们的信息?我找不到怎么写这个,所以我不得不在这里问。还是人们通常使用一些chrome扩展(或其他什么)来生成这些内容?@Aman不,我发现使用chrome或Firefox扩展来生成XPath倾向于使用索引,这使得它们更容易受到html结构细微变化的影响。您可以了解xpath,这里有很多关于堆栈溢出的非常好的问题和答案,用于更复杂的内容。