Posts by britodfbr • 688 points
73 posts
-
1
votes1
answer229
viewsA: Python: how to edit tag with bs4
I’ve come to this solution. I want to share to multiply the knowledge. import os import re from bs4 import BeautifulSoup __author__ = '@britodfbr' with open(os.path.abspath('../data/D9255.htm')) as…
-
0
votes1
answer229
viewsQ: Python: how to edit tag with bs4
I have an html code, well polluted with Style in almost all tags, plus tags <font><span> unnecessary. How can I use beautifulsoup, to remove only attrs=style in <p> and the tags…
-
0
votes0
answers45
viewsQ: IDE Pycharm on Windows
I already have a habit of using Pycharm over GNU/Linux, and by force majeure I will have to use it over Windows. The problem is this: When running the python script from the IDE, a python Crawler,…
-
0
votes2
answers481
viewsA: Decode HTML entities in a Python string
It is also possible to use Beautifulsoup, bs4 for Py3+ or Bs for Py3-, which in addition to converting the HTML encoding to ascii, also allows working with the HTML elements individually (if there…
-
1
votes1
answer168
viewsQ: Python: Cleaning html code
Using python, what would be the easy way to clear tag parameters coming from microsoft tools? Initially I’m trying to transform via Beautiful Soup, but I’m open to all suggestions! :D In this way:…
-
0
votes2
answers64
viewsQ: CSS: How to insert an image element centered on paper?
Personal how can I insert a centralized image element as logo into an html document, to set format "@media print"? In the model I’m applying on screen, for viewing on screen. <html>…
-
0
votes1
answer895
viewsQ: Awesome fonts: how to change the font in a:Hover via CSS?
How to change the font from "Regular Icons" to "Solid Icons" via CSS. No https://fontawesome.com/cheatsheet both have the same code. <!DOCTYPE html> <html> <head> <title>Page…
-
0
votes2
answers582
viewsA: CSS with custom list-style-type on awesome fonts
Final result after help from colleague @hugocsl. <!DOCTYPE html> <html> <!-- http://fontawesome.io/cheatsheet/ --> <head> <link…
-
1
votes2
answers582
viewsQ: CSS with custom list-style-type on awesome fonts
How can I change the list-style-type Bullet to a fontawesome icon? <!DOCTYPE html> <html> <head> <title>Page Title</title> <link rel="stylesheet"…
-
0
votes2
answers92
viewsQ: CSS with Font Awesome
How to replace the image of the CSS example available in https://pastebin.com/Bm1k1Pjs by Font Awesome? Follows code below: <blockquote style=' font: 14px/20px italic Times, serif; padding-left:…
-
2
votes2
answers61
viewsQ: default values for namedtuple
When creating a class I can set some default values: class Point: def __init__(self, x, y, z=0): self.x = x self.y = y self.z = z How to proceed the same way for namedtuple? from collection import…
-
1
votes1
answer962
viewsQ: Web Scraping - convert HTML table to python Dict
I’m trying to turn an HTML table into dict@python, I came across some problems and I ask for your help. Go as far as I can go... def impl12(url='http://www.geonames.org/countries/', tmout=2): import…
-
1
votes2
answers164
viewsQ: How to coverter string for timestamp object?
How can I transform a string containing a date, example: 'Thu Jul 27 13:54:22 2017', in a datetime object, or time?
-
0
votes2
answers164
viewsA: How to coverter string for timestamp object?
def execute01(): ''' Converte string para objeto time''' import time str_date = 'Thu Jul 27 13:54:22 2017' obj_date = time.strptime(str_date, "%a %b %d %H:%M:%S %Y") return time.strftime('%Y/%m/%d',…
-
2
votes3
answers280
viewsA: How do I block access to setting parameters in a class?
The ending with the help of Anderson Woss: import math class FormaGeometrica: __slots__ = () def get_area(self): raise NotImplementedError(NotImplemented) def get_perimetro(self): raise…
-
0
votes3
answers4922
viewsA: python recursive function to compute sum of the elements of a list
Recursion is the technique where a method or function calls itself to arrive at the result. I implemented this in pythonic form: def soma_lista(lista=list()): ''' Calcula a somatória dos elementos…
-
3
votes3
answers7867
viewsA: Instantiate a Python class using an object as argument
In your need in the class initializer, Voce implements key and value. This characterizes dictionary. However the call is using the list notation. Substitute: def __init__(self, *attrs): if attrs:…
-
4
votes3
answers280
viewsQ: How do I block access to setting parameters in a class?
import math class Circulo(): def __init__(self): super() self.__raio = None def get_perimetro(self): return 2 * math.pi * self.raio def get_area(self): return math.pi * self.raio ** 2 @property def…
-
0
votes2
answers5037
viewsA: Decimal to hexadecimal conversion
In this example below I used doctest to validate the results. def int2hex(n): ''' :param n: int :return: str >>> int2hex(10) 'A' >>> int2hex(15) 'F' >>> int2hex(32) '20'…
-
0
votes0
answers25
viewsQ: conversion of Unittest Python2 to Python3
I have some free time and am updating in Python3. I came across a problem in the execution of the unittest, and I believe you can help me. Error: File…
-
0
votes2
answers928
viewsA: Read data in real time
Excellent answer from Mr Fsola. I have a suggestion to make it more pythonic. Replacing replace with strip, we reduce a line of code. #Python3 import time def monitorar(logfile='file.log'): with…
python-3.xanswered britodfbr 688 -
4
votes3
answers6745
viewsA: How to validate whether it is a vowel without writing all the letters of the alphabet
def isVogal(letra): vogais = 'aeiou' return letra.lower() in vogais def vogal(): print(isVogal(input("Digite uma letra: "))) vogal() I created 2 methods, where the first one returns True for vowel…
-
0
votes2
answers57
viewsA: What function do I use to return or show all the equal numbers in a list of 20 numbers?
import collections n = [] for i in range(20): n.append(random.randrange(6)) print(n) # esta é a lista m = collections.defaultdict(int) for i in n: m[i] += 1 print(dict(m)) # apresenta o item e a…