Grab 2 items in 1 string?
Question: I'm not smart with this as u can tell. I'm looking to grab 2 things with 1
line.

eg

    
    
    <a href="(URL TO GRAB)">(TITLE TO GRAB)</a>
    <a href="(URL TO GRAB)" rel="nofollow">(TITLE TO GRAB)</a>
    

The Urls and Titles always begin with http or https

    
    
    <a href="http(s)://www.whatever.com/1.html">http(s)://www.whatever.com/1.html</a>
    <a href="http(s)://www.whatever.com/2.html" rel="nofollow">http(s)://www.whatever.com/2.html</a>
    

I have tried the following with replace method to eliminate `rel="nofollow">`
with a blank space but there are 130 some other `re="variables'>` and I only
want the `"nofollow"` one and don't want to write 130 some replace.

    
    
    item_infos=<a href="([^"]+)"([^"]+)</a>
    item_order=url.tmp|title.tmp
    item_skill=rss
    

It's python for kodi/xbmc scraping reddit.

Edit: Thanks for your help folks. I am currently using the one provided by Jon

    
    
    item_infos=<a href="([^"]+)"[^>]*>([^<]+)</a>
    

Seems to work but i wont know till the thread is updated later. Thanks again
:)


Answer: You can use a HTML parser such as BeautifulSoup. Here's an example:

    
    
    from bs4 import BeautifulSoup
    
    html = '''<a href="http(s)://www.whatever.com/1.html">http(s)://www.whatever.com/1.html</a>
    <a href="http(s)://www.whatever.com/2.html" rel="nofollow">http(s)://www.whatever.com/2.html</a>'''
    
    soup = BeautifulSoup(html)
    print 'href :', soup.a['href']
    print 'title :', soup.a.text
    
    for tag in soup.find_all('a'):
        print 'href: {}, title: {}'.format(tag['href'], tag.text)
    

**Output**

    
    
    href : http(s)://www.whatever.com/1.html
    title : http(s)://www.whatever.com/1.html
    href: http(s)://www.whatever.com/1.html, title http(s)://www.whatever.com/1.html
    href: http(s)://www.whatever.com/2.html, title http(s)://www.whatever.com/2.html
    

