Example #1
0
def parseInstructions(instructionList):
    logging.debug("Parsing instructions")
    instructions = []
    for instruction in instructionList:
        logging.debug("Instruction: {0}".format(instruction))
        instructions.append(instructionSet.InstructionSet(instruction))
    return instructions
Example #2
0
 def test_replace_id_and_class(self):
     htmlText = '<html><body><p id="someName" class="awesome time">Some Text</p><p class="sibling">sibling text</p></body></html>'
     resultText = b'<html><body><p id="someOtherName" class="time blah">Some Text</p><p class="sibling">sibling text</p></body></html>'
     instructions = 'p#someName.awesome -> p#someOtherName.blah'
     element = html.fromstring(htmlText)
     instruction = instructionSet.InstructionSet(instructions)
     result = xmlsrr.processInstructions(element, instruction)
     self.assertEqual(resultText, etree.tostring(result))
Example #3
0
 def test_remove_attribute_add_class(self):
     htmlText = '<html><body><p id="someName" style="text-indent:0px; margin-left: 26px;list-style-position:outside;" class="awesome time">Some Text</p><p class="sibling">sibling <em>text</em></p></body></html>'
     resultText = b'<html><body><p id="someName" class="awesome time listIndent1">Some Text</p><p class="sibling">sibling <em>text</em></p></body></html>'
     instructions = '[style=text-indent:0px; margin-left: 26px;list-style-position:outside;] -> .listIndent1'
     element = html.fromstring(htmlText)
     instruction = instructionSet.InstructionSet(instructions)
     result = xmlsrr.processInstructions(element, instruction)
     self.assertEqual(resultText, etree.tostring(result))
Example #4
0
 def test_replace_element(self):
     htmlText = '<html><body><p id="someName" class="awesome time">Some Text</p><p class="sibling">sibling text</p></body></html>'
     resultText = b'<html><body><div id="someName" class="awesome time">Some Text</div><div class="sibling">sibling text</div></body></html>'
     instructions = 'p -> div'
     element = html.fromstring(htmlText)
     instruction = instructionSet.InstructionSet(instructions)
     result = xmlsrr.processInstructions(element, instruction)
     self.assertEqual(resultText, etree.tostring(result))
Example #5
0
 def test_remove_id(self):
     htmlText = '<html><body><p id="someName" class="awesome time">Some Text</p><p class="sibling">sibling <em>text</em></p></body></html>'
     resultText = b'<html><body><p class="sibling">sibling <em>text</em></p></body></html>'
     instructions = '/#someName'
     element = html.fromstring(htmlText)
     instruction = instructionSet.InstructionSet(instructions)
     result = xmlsrr.processInstructions(element, instruction)
     self.assertEqual(resultText, etree.tostring(result))