Quantcast
Channel: python Get a link from string - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Mauricio Cortazar for python Get a link from string

$
0
0

You can use regex for that with something like:

import rec = re.search("<a href=\".*?(?=\")", yourDict["body"].decode("utf-8"))print(c.group())

but is much better if you find a package like parsel because you extract the html with xpath and not with regex, check this

EDIT

I use the regular expression because is the shortest and the fastest way with no need of download a package, but if your response changes drastically I recommend parsel for that. Example:

from parsel import Selectorsel = Selector(text=yourDict["body"].decode("utf-8"))url = sel.xpath('//a[@target="_blank"]/@href').extract_first()

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>