相关疑难解决方法(0)

正则表达式使用Python从HTML中的href属性中提取URL

可能重复:
检查字符串是否为有效URL的最佳正则表达式是什么?

考虑如下字符串:

string = "<p>Hello World</p><a href="http://example.com">More Examples</a><a href="http://example2.com">Even More Examples</a>"
Run Code Online (Sandbox Code Playgroud)

我怎么能用Python在锚标记的href中提取网址?就像是:

>>> url = getURLs(string)
>>> url
['http://example.com', 'http://example2.com']
Run Code Online (Sandbox Code Playgroud)

谢谢!

python regex url

79
推荐指数
2
解决办法
14万
查看次数

在Python中提取URL

关于:使用Python在文本中查找超链接(与twitter相关)

如何只提取网址,以便将其放入列表/数组?


编辑

让我澄清一下,我不想将URL解析成碎片.我想从字符串的文本中提取URL以将其放入数组中.谢谢!

python url parsing

35
推荐指数
6
解决办法
7万
查看次数

如何删除Python中字符串中的任何URL

我想删除字符串中的所有URL(用""替换它们)我搜索过但却找不到我想要的东西.

例:

text1
text2
http://url.com/bla1/blah1/
text3
text4
http://url.com/bla2/blah2/
text5
text6
http://url.com/bla3/blah3/
Run Code Online (Sandbox Code Playgroud)

我希望结果如下:

text1
text2
text3
text4
text5
text6
Run Code Online (Sandbox Code Playgroud)

python regex url replace python-2.7

31
推荐指数
11
解决办法
7万
查看次数

用于从Twitter推文中删除URL链接的表达式

我只是想在字符串中找到并替换所有出现的twitter url(tweet):

输入:

这是一条带有网址的推文:http://t.co/0DlGChTBIx

输出:

这是一条带有网址的推文:

我试过这个:

p=re.compile(r'\<http.+?\>', re.DOTALL)
tweet_clean = re.sub(p, '', tweet)
Run Code Online (Sandbox Code Playgroud)

python regex string

13
推荐指数
1
解决办法
3万
查看次数

正则表达式html文本中的链接

我希望这个问题不是RTFM问题.我正在尝试编写一个Python脚本,从标准HTML网页(<link href...标签)中提取链接.我在网上搜索匹配的regexen,发现了许多不同的模式.是否有任何商定的标准正则表达式匹配链接?

亚当

更新: 我实际上正在寻找两个不同的答案:

  1. 什么是解析HTML链接的库解决方案.美丽的汤似乎是一个很好的解决方案(谢谢,Igal Serbancletus!)
  2. 可以使用正则表达式定义链接​​吗?

html python regex href hyperlink

7
推荐指数
3
解决办法
1万
查看次数

分解HTML以链接文本和目标

给出像这样的HTML链接

<a href="urltxt" class="someclass" close="true">texttxt</a>
Run Code Online (Sandbox Code Playgroud)

我该如何隔离网址和文字?

更新

我正在使用Beautiful Soup,我无法弄清楚如何做到这一点.

我做到了

soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url))

links = soup.findAll('a')

for link in links:
    print "link content:", link.content," and attr:",link.attrs
Run Code Online (Sandbox Code Playgroud)

我明白了

*link content: None  and attr: [(u'href', u'_redirectGeneric.asp?genericURL=/root    /support.asp')]*  ...
...
Run Code Online (Sandbox Code Playgroud)

为什么我错过了内容?

编辑:详细说明'卡住'建议:)

html python regex beautifulsoup

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×6

regex ×5

url ×3

html ×2

beautifulsoup ×1

href ×1

hyperlink ×1

parsing ×1

python-2.7 ×1

replace ×1

string ×1