tags

Strip the first (top level) tag in Beautifulsoup

Strip the first (top level) tag in Beautifulsoup Question: I create a soup: from bs4 import BeautifulSoup soup = BeautifulSoup("<div><p>My paragraph <a>My link</a></p></div>", "html.parser") I want to strip the first top-level tag to reveal its contents, regardless of the tag: <p>My paragraph<a>My link</a></p> with all the children. So I don’t want to find and replace …

Total answers: 2

Test if children tag exists in beautifulsoup

Test if children tag exists in beautifulsoup Question: i have an XML file with an defined structure but different number of tags, like file1.xml: <document> <subDoc> <id>1</id> <myId>1</myId> </subDoc> </document> file2.xml: <document> <subDoc> <id>2</id> </subDoc> </document> Now i like to check, if the tag myId exits. So i did the following: data = open(“file1.xml”,’r’).read() xml …

Total answers: 8

Django Tag model design

Django Tag model design Question: I am wondering if the following is the correct way to create tagging system for images and being able to render a tag cloud: from django.db import models class Tag(models.Model): word = models.CharField(max_length=35) slug = models.CharField(max_length=250) created_at = models.DateTimeField(auto_now_add=False) def __unicode__(self): return self.word class Photo(models.Model): slug = models.CharField(max_length=250) filename = …

Total answers: 2

BeautifulSoup: extract text from anchor tag

BeautifulSoup: extract text from anchor tag Question: I want to extract: text from following src of the image tag and text of the anchor tag which is inside the div class data I successfully manage to extract the img src, but am having trouble extracting the text from the anchor tag. <a class=”title” href=”http://www.amazon.com/Nikon-COOLPIX-Digital-Camera-NIKKOR/dp/B0073HSK0K/ref=sr_1_1?s=electronics&amp;ie=UTF8&amp;qid=1343628292&amp;sr=1-1&amp;keywords=digital+camera”>Nikon COOLPIX …

Total answers: 8

tag generation from a text content

tag generation from a text content Question: I am curious if there is an algorithm/method exists to generate keywords/tags from a given text, by using some weight calculations, occurrence ratio or other tools. Additionally, I will be grateful if you point any Python based solution / library for this. Thanks Asked By: Hellnar || Source …

Total answers: 5