簡體   English   中英

在沒有BeautifulSoup的情況下,使用python提取網頁上鏈接的最簡單方法是什么?

[英]What's the easiest way to extract the links on a web page using python without BeautifulSoup?

我正在使用cygwin,但未安裝BeautifulSoup。

如果您不太在意性能,則可以使用正則表達式:

import re
linkre = re.compile(r"""href=["']([^"']+)["']""")
links = linkre.findall(your_html)

如果只想使用http://鏈接中的鏈接,則將表達式更改為:

linkre = re.compile(r"""href=["']http:([^"']+)["']""")

或者,如果有可能您的鏈接周圍沒有html,則可以將“”作為可選。

暫無
暫無

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

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