Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <a href="urltxt" class="someclass" close="true">texttxt</a>
- soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url))
- links = soup.findAll('a')
- for link in links:
- print "link content:", link.content," and attr:",link.attrs
- *link content: None and attr: [(u'href', u'_redirectGeneric.asp?genericURL=/root /support.asp')]* ...
- ...
- soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url).read())
- import urlparse, urllib
- from BeautifulSoup import BeautifulSoup
- url = "http://www.example.com/index.html"
- source = urllib.urlopen(url).read()
- soup = BeautifulSoup(source)
- for item in soup.fetchall('a'):
- try:
- link = urlparse.urlparse(item['href'].lower())
- except:
- # Not a valid link
- pass
- else:
- print link
- soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url))
- for link in soup.findAll('a'):
- print link.attrs, link.contents
- /<as+[^>]*?href="([^"]*)".*?>(.*?)</a>/
- '<a href="url" close="true">text</a>'
- // Parts: "url", "text"
- '<a href="url" close="true">text<span>something</span></a>'
- // Parts: "url", "text<span>something</span>"
Add Comment
Please, Sign In to add comment