1
I am trying to extract source code from an html file with the following style:
<div class="both"></div>
<div class="st-box" id="source-code">
<h3>SOURCE CODE</h3>
<div class="wrap code-answer-1">
<pre id="code" class="code-2">#include <bits/stdc++.h>
using namespace std;
int main ()
{
double A, B, C;
scanf ("%lf %lf %lf", &A, &B, &C);
printf ("TRIANGULO: %.3lf\n", (A * C) / 2.0);
printf ("CIRCULO: %.3lf\n", C * C * 3.14159);
printf ("TRAPEZIO: %.3lf\n", ((A + B) * C) / 2.0);
printf ("QUADRADO: %.3lf\n", B * B);
printf ("RETANGULO: %.3lf\n", A * B);
system ("pause");
return 0;
}</pre>
</div>
</div>
</ul>
</div>
Using the following code:
def getCode(self, id):
return self.getPage('https://www.urionlinejudge.com.br/judge/'+self.lang+'/runs/code/'+id).find("pre ", {"id": "code"}).text
However I get the following error:
Attributeerror: 'Nonetype' Object has no attribute 'text'
How to solve?
You forgot to put the complete error. If the error is even on this line, it means that it did not find the element
<pre id="code">
in this html.– nosklo
Managed to solve your problem? Still have some questions?
– Rafael Barros