簡體   English   中英

從網站源代碼中的超鏈接中提取 URL

[英]Extract URL from Hyperlink inside source code of a website

我正在嘗試使用 BeautifulSoup 來解析來自Xtremepapers的 PDF 文件:

HTML 源代碼位於:

但是,錨標記中的href屬性包含一種指向特定 PDF 下載頁面的超鏈接,而不是直接下載鏈接。

我需要幫助提取下載鏈接並通過一些 Python 腳本將其保存到我的硬盤驅動器。

好的,我對此很陌生,所以這可能是顛簸的。 但看起來您使用的是檢查元素而不是開發人員工具。

如果你使用開發者工具,點擊刷新到網站然后點擊數學名稱,你會看到真正的 html。 你可以看到每個 pdf 是這樣鏈接的:

 a_tag = <a class="autoindex_a" href="9709_2007_syllabus.pdf">
<img width="16" height="16" alt="[pdf]" src="/images/icons/pdf.png" />
9709_2007_syllabus.pdf </a> 

end_url = a_tag.get('href', None)

print(end_url)

>>9709_2007_syllabus.pdf

然后,您只需將該位附加到網站“ https://papers.xtremepape.rs/CAIE/AS%20and%20A%20Level/Mathematics%20(9709)/ ”的 url

full_url = 'https://papers.xtremepape.rs/CAIE/AS%20and%20A%20Level/Mathematics%20(9709)/' + end_url

print(full_url)  >>https://papers.xtremepape.rs/CAIE/AS%20and%20A%20Level/Mathematics%20(9709)/9709_2007_syllabus.pdf

So you end with this link which takes you to thd pdf: https://papers.xtremepape.rs/CAIE/AS%20and%20A%20Level/Mathematics%20(9709)/9709_2007_syllabus.pdf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM