【发布时间】:2020-07-30 00:55:35
【问题描述】:
我正在构建一个网络爬虫,我不知道如何辨别元素属性。
目前,我正在从左侧移动一个“扫描头”来编写代码,并寻找某些字符串来标记属性。例如,到目前为止,我一直在寻找 =" 来决定某个属性可能存在的位置。
问题已经开始出现,因为编写 HTML 有多种“有效”方式。
例如,来自this home depot page,源代码有两个特定元素:
<a href="https://www.homedepot.com/b/Featured-Products-Ryobi/N-5yc1vZ1z18hrf?cm_sp=vanity-_-ryobi-_-APR19" target="_blank" style="color:#F96302;">Learn More about the RYOBI Platform Here</a>
<a href=https://www.homedepot.com/c/electronics_recycling_programs style=color:#F96302; target=_blank>Click here for more information on Electronic Recycling Programs</a>
这让刮刀很头疼。第一个元素被抓取,但第二个元素没有任何=" 可以找到。我也不能只查找=,因为这会产生误报,就像在第一个元素中有...sp=vanity... 无法正确解析。
如何处理 HTML 的多种语法?
编辑:到目前为止我一直在使用 C++
【问题讨论】:
-
您使用哪种语言?
-
好的,谢谢,我正在使用 C++
标签: html c++ web web-scraping attributes