![](/img/trans.png)
[英]How to get raw html with absolute links paths when using 'requests-html'
[英]How do I get all the links on a web page using requests-html
我是 web 解析的新手,我想制作一個程序來獲取 web 頁面上的所有內部和外部鏈接,我根本不知道該怎么做,我所寫的就是這個
from requests_html import *
sss = HTMLSession()
k = sss.get('https://en.wikipedia.org/wiki')
hhh = HTML(html=k.html.html)
print(hhh.find('href'))
我不知道為什么當href標簽無處不在時它會打印[]提前謝謝你
您可以使用下面的代碼獲取所有內部和外部鏈接。 該代碼將所有相對鏈接轉換為絕對鏈接。
from requests_html import HTMLSession
base_url = 'https://en.wikipedia.org'
sss = HTMLSession()
k = sss.get('https://en.wikipedia.org/wiki')
links = k.html.absolute_links
print(links)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.