AGI_2404期_实时网页信息爬取(一)网页结构问题2 --林辉老师 #462
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: HswOAuth/llm_course#462
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
2、我尝试举一反三,我随便打开了一个网址,查看网页源码结构,发现完全与案例不同,找不到入口和起始点? 请帮忙看下;
天眼查中的网页比较特殊,也是比较好爬取的,他的数据是以json格式返回给我们的,比较好处理
这位学员的这个网址中的数据是嵌入在html页面中,获取起来会比较麻烦,需要对每一个数据都单独进行获取,但是是有工具可以获取到的,比如老师上课使用的xpath工具,xpath的教程在这个链接中https://www.runoob.com/xpath/xpath-tutorial.html,
对于这位学员的图片中的数据在pythhon中使用xpath可以通过如下方式获取
以获取“南宋抗金名将,民族英雄”为例:
c_list = etree.HTML(r.text)
j_data = c_list.xpath('//table[@id="tjtable"]//div[@id="tctitle"]//a[@class="blue14b"]//text()')[0]
其中r.text是获取到的网页源文件,j_data为获取到的结果字符串
老师,这块获取需要的内容时,《//table[@id="tjtable"]//div[@id="tctitle"]//a[@class="blue14b》 标签只能自己手动写吗?有没有现成的工具,输入网页内容 指定需要获取的那部分数据,自动生成标签《//table[@id="tjtable"]//div[@id="tctitle"]//a[@class="blue14b》呢
好的,多谢老师