siana1998 2021-11-15 17:34 采纳率: 100%
浏览 60
已结题

关于#python#的问题:通过request.get获取的源代码不全

网址:# http://georoc.mpch-mainz.gwdg.de/georoc/Start.asp #
想爬取网页左侧导航rock内的所有csv文件,但是爬取的源代码里没有csv地址,请问如何解决,谢谢各位能人!

img

这是我的代码:

archive_url = "http://georoc.mpch-mainz.gwdg.de/georoc/Start.asp"  # 网址链接

def get_video_links():
    r = requests.get(archive_url)
    soup = BeautifulSoup(r.content, 'html.parser')
    print(soup)
    item = soup.find_all('tb', class_="arialtb12")     #csv所在代码位置
    print(item)

if __name__ == "__main__":
    video_links = get_video_links()

以下是我获取的html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<!-- saved from url=(0049)http://georoc.mpch-mainz.gwdg.de/georoc/Start.asp -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">



<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="description" content="GEOROC - Geochemical Database on magmatic Rocks">
<meta name="keywords" lang="en-us" content="database, analyses, volcanic rocks, mantle xenoliths, major elements, trace element,
     concentrations, radiogenic, nonradiogenic, isotope ratios, analytical, ages, whole rocks, volcanic, glasses, minerals, inclusions">
<meta name="keywords" lang="en" content="database, analyses, volcanic, rocks, mantle xenoliths, major elements, trace element,
     concentrations, radiogenic, nonradiogenic, isotope ratios, igneous, analytical, ages, whole rocks, volcanic, glasses, minerals, inclusions">
<meta name="keywords" lang="de" content="Datenbank, geochemie, spurenelement, oxid, gehalte, vulkanite, isotopenverh鋖tnisse, magmatite, xenolithe, analytik, minerale">
<meta name="keywords" lang="it" content="Database , geochimica , contenuti, ossido, oligoelementi , vulcanici , rapporti isotopici , rocce ignee , xenoliti , analisi , minerali">

<title>Geochemical Rock Database-Query</title>

</head>

<frameset rows="100%" cols="18%,82%">
<frame frameborder="0" marginwidth="0" src="./Geochemical Rock Database-Query_files/Query.html" name="Query">
<frame frameborder="0" marginwidth="0" src="./Geochemical Rock Database-Query_files/QueryBlank.html" name="Search">
<noframes>
<body>

<table style="background-color:#99CCFF; padding:1px; border-width:3px; border-color: #000099; height: 8%; width: 40%; margin-left:auto; margin-right:auto; ">
<tr>
<td style="text-align:center;">
<a href="Start.asp"><b>Home</b> |</a> <a href="Content.htm"><b>Content</b> |</a>
</td>
</tr>
</table>

<h1 style="text-align:center;"><b>Query by</b></h1>
<p style="text-align:center;">
&nbsp;</p>
<h2 style="text-align:center;">
<a href="Authors.asp?Frames=no">1. Bibliography</a></h2>
<br/>
<h2 style="text-align:center;">
<a href="QueryLoc.asp?Frames=no">2. Location</a></h2>
<br/>
<h2 style="text-align:center;">
<a href="QueryChem.asp?Frames=no">3. Chemistry</a></h2>
<br/>
<br/>
<br/>

<table style="height: 8%; width:auto; margin-left:auto; margin-right:auto;">
<tr>
<td>
<a href="http://www.mpic.de">&copy; MPI f&uuml;r Chemie, Mainz, Germany</a>&nbsp;
</td>
</tr>
</table>

<p style="text-align:center;">
<span style="font-family: Arial; color: #000033">&nbsp;&nbsp;&nbsp;State: 05/01/2018    </span></p>
</body>
</noframes>
</frameset>

</html>
  • 写回答

3条回答 默认 最新

  • 关注

    你检查下这个网页中的内容是不是通过js代码读取外部json数据来动态更新的。
    requests只能获取网页的静态源代码,动态更新的内容取不到。
    对于动态更新的内容要用selenium 来爬取。

    或者是通过F12控制台分析页面数据加载的链接,找到真正json数据的地址进行爬取。

    在页面上点击右键,右键菜单中选 "查看网页源代码"。

    img


    这样看到的才是网页的静态源代码。
    如果这个网页的静态源代码中有你需要爬取的内容,就说明该页面没有动态内容,可以用requests爬取。
    否则就说明该页面的内容是动态更新的,要用selenium 来爬取.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月24日
  • 已采纳回答 11月16日
  • 创建了问题 11月15日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么