Python - how to extract href using BeautifulSoup without selenium (onclick)

K.k

this is element.

<img src="http://dcimg6.dcinside.co.kr/viewimage.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f244141456484cb174854719ce631af568a8c297d4e29cc59286bf0d77bcf8d9267e7297e17913fdd84522b3d3" style="cursor:pointer;" onclick="javascript:imgPop('http://image.dcinside.com/viewimagePop.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f24450460016bd8e2258cb95ccf2b058e84f237054da6dbbc48af67310bf0bff50c529f1331053edf6','image','fullscreen=yes,scrollbars=yes,resizable=no,menubar=no,toolbar=no,location=no,status=no');">

i want to extract here "http://image.dcinside.com/viewimagePop.php?id=2fbcc323e7d334aa51b1d3a240&no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f24450460016bd8e2258cb95ccf2b058e84f237054da6dbbc48af67310bf0bff50c529f1331053edf6"

how to extract it?

Maxim Kukhtenkov

This should work with BeautifulSoup v3 and v4.

content = """
    <img src="http://dcimg6.dcinside.co.kr/viewimage.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f244141456484cb174854719ce631af568a8c297d4e29cc59286bf0d77bcf8d9267e7297e17913fdd84522b3d3" style="cursor:pointer;" onclick="javascript:imgPop('http://image.dcinside.com/viewimagePop.php?id=2fbcc323e7d334aa51b1d3a240&amp;no=24b0d769e1d32ca73fef84fa11d028318f52c0eeb141bee560297996d466c894cf2d16427672bba3d66d67f24450460016bd8e2258cb95ccf2b058e84f237054da6dbbc48af67310bf0bff50c529f1331053edf6','image','fullscreen=yes,scrollbars=yes,resizable=no,menubar=no,toolbar=no,location=no,status=no');">
"""

soup = BeautifulSoup(content)

onclick = soup.find('img').get('onclick')

js_item = onclick.split(',')[0]

link = js_item.replace('javascript:imgPop(', '').replace("'", "")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract href content using beautifulsoup in python

how to extract a href content from a website using BeautifulSoup package in python

How to extract the href attribute of the first search result using Selenium and Python

How to extract the text through a href using Selenium and Python

How to extract link from href using beautifulsoup

How to extract url from onclick javascript using selenium : Python

How to extract onClick url using beautifulsoup

Selenium how to extract href and label name Python?

how to extract all the href from the a tags and test if they start with '/' or not using beautifulsoup? - Python

How to extract the href link inside a particular td in python with beautifulsoup

How to extract the href attribute after a particular th in the wikipage infobox through Selenium or lxml using Python

Extract href by class Selenium Python

Extract data from multiple page using python selenium/Beautifulsoup

How can i extract href from this html using selenium?

How to locate the href element using selenium python

How to extract all href from a class in Python Selenium?

How to extract list items with a href by BeautifulSoup?

How to find element using onclick in selenium Python?

How to extract text inside span without class name with BeautifulSoup in python

How to extract the Subtotal Price using Selenium and Python

How to extract multiple text using selenium python

How to extract the text elements using Selenium in Python?

How to extract <figure> images using Selenium in python?

How to get complete href links using beautifulsoup in python

How do I get the onclick text from <a href onclick="sometext" in Java using selenium

Extract iFrame content using Selenium and BeautifulSoup

How to click Onclick from <a without text Javascript form using Selenium?

Extract Href using scrapy python

Extract iframes using BeautifulSoup with Python