AttributeError: 'NoneType' object has no attribute 'previous_sibling'
filing_doc_text = filing_documents.find('text').extract()
#Get all the thematic breaks. The thematic breaks are in non string form and this process is getting the thematic breaks with header
#and the width of 100%.
all_thematic_breaks = filing_doc_text.find_all('hr',{'width':'100%'})
#The following code parses the page number from the page and therefore you can print exact number on the pages.
# define a list to house all the page numbers
all_page_numbers = []
for thematic_break in all_thematic_breaks:
# this would grab the page number tag.
page_number = thematic_break.parent.parent.previous_sibling.previous_sibling
print(page_number)
# this would grab the page number text
page_number = page_number.get_text(strip=True)
# store it in the list.
all_page_numbers.append(page_number)
It shows error when i print page_number
Traceback (most recent call last): File "c:\Users\Vanya\Desktop\FINAL\our_code (1).py", line 291, in page_number = thematic_break.parent.parent.previous_sibling.previous_sibling AttributeError: 'NoneType' object has no attribute 'previous_sibling'
See also questions close to this topic
-
Error non-linear-regression python curve-fit
Hello guys i want to make non-linear regression in python with curve fit this is my code:
#fit a fourth degree polynomial to the economic data from numpy import arange from scipy.optimize import curve_fit from matplotlib import pyplot import math x = [17.47,20.71,21.08,18.08,17.12,14.16,14.06,12.44,11.86,11.19,10.65] y = [5,35,65,95,125,155,185,215,245,275,305] # define the true objective function def objective(x, a, b, c, d, e): return ((a)-((b)*(x/3-5)))+((c)*(x/305)**2)-((d)*(math.log(305))-math.log(x))+((e)*(math.log(305)-(math.log(x))**2)) popt, _ = curve_fit(objective, x, y) # summarize the parameter values a, b, c, d, e = popt # plot input vs output pyplot.scatter(x, y) # define a sequence of inputs between the smallest and largest known inputs x_line = arange(min(x), max(x), 1) # calculate the output for the range y_line = objective(x_line, a, b, c, d, e) # create a line plot for the mapping function pyplot.plot(x_line, y_line, '--', color='red') pyplot.show()
this is my error :
Traceback (most recent call last): File "C:\Users\Fahmi\PycharmProjects\pythonProject\main.py", line 16, in popt, _ = curve_fit(objective, x, y) File "C:\Users\Fahmi\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\optimize\minpack.py", line 784, in curve_fit res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs) File "C:\Users\Fahmi\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\optimize\minpack.py", line 410, in leastsq shape, dtype = _check_func('leastsq', 'func', func, x0, args, n) File "C:\Users\Fahmi\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\optimize\minpack.py", line 24, in _check_func res = atleast_1d(thefunc(((x0[:numinputs],) + args))) File "C:\Users\Fahmi\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\optimize\minpack.py", line 484, in func_wrapped return func(xdata, params) - ydata File "C:\Users\Fahmi\PycharmProjects\pythonProject\main.py", line 13, in objective return ((a)-((b)(x/3-5)))+((c)(x/305)**2)-((d)(math.log(305))-math.log(x))+((e)(math.log(305)-(math.log(x))**2)) TypeError: only size-1 arrays can be converted to Python scalars
thanks before
-
beautifulsoup (webscraping) not updating variables when HTML text has changed
I am new to python and I cant understand why this isn't working, but I've narrowed down the issue to one line of code.
The purpose of this bot is to scrape HTML from a website (using beautiful and post to discord when the text changes. I use FC2 and FR2 (flightcategory2 and flightrestrictions2) as memory variables for the code to check against every time it runs. If they're the same, the code waits for _ minutes and checks again, if they're different it posts it.
However when running this code, the variables "flightCategory" "flightRestrictions" change the first time the code runs, but for some reason stop changing when the HTML text on the website changes. the line in question is this if loop.
if 1==1: # using 1==1 so this loop constantly runs for testing, otherwise I have it set for a time flightCategory, flightRestrictions = und.getInfo()
When debugging mode, the code IS run, but the variables in the code don't update, and I am confused as to why they would update the first time the code is run, but not sequential times. This line is critical to the operation of my code.
Here's an abbreviated version of the code to make it easier to read. I'd appreciate any help.
FC2 = 0 FR2 = 0 flightCategory = "" flightRestrictions = "" class UND: def __init__(self): page = requests.get("http://sof.aero.und.edu") self.soup = BeautifulSoup(page.content, "html.parser") def getFlightCategory(self): # Takes the appropriate html text and sets it to a variable flightCategoryClass = self.soup.find(class_="auto-style1b") return flightCategoryClass.get_text() def getRestrictions(self): # Takes the appropriate html text and sets it to a variable flightRestrictionsClass = self.soup.find(class_="auto-style4") return flightRestrictionsClass.get_text() def getInfo(self): return self.getFlightCategory(), self.getRestrictions() und = UND() while 1 == 1: if 1==1: #using 1==1 so this loop constantly runs for testing, otherwise I have it set for a time flightCategory, flightRestrictions = und.getInfo() (scrape the html from the web) if flightCategory == FC2 and flightRestrictions == FR2: # if previous check is the same as this check then skip posting Do Something elif flightCategory != FC2 or flightRestrictions != FR2: # if any variable has changed since the last time FC2 = flightCategory # set the comparison variable to equal the variable FR2 = flightRestrictions if flightRestrictions == "Manager on Duty:": # if this is seen only output category Do Something elif flightRestrictions != "Manager on Duty:": Do Something else: print("Outside Time") time.sleep(5) # Wait _ seconds. This would be set for 30 min but for testing it is 5 seconds. O
-
Need to reload vosk model for every transcription?
The vosk model that I'm using is vosk-model-en-us-aspire-0.2 (1.4GB). Every time need quite amount of time to load the vosk model. Is it necessary to recreate the vosk object for every time? It take many time to load the model, if we only load model once. It can save up at least half of the time.
-
I want to generate a parse tree please
. Generate the parse tree(s) for the following grammar for string 1+2*3
expression = <integer>| <expression> <operator> <expression> operator = + | - | * | / integer = <nonzero digit> { <digit> } digit = 0 | <nonzero digit> nonzero digit = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
-
How to use numbers in the JSON path with node.js?
I have this JSON file: (EDITED)
{ "user": { "S-1-5-21-2659826518-2396530539-1407762326-1001": { "username":"xyz", "password":"xyz@123", "email":"xyz@xyz.com", "uid": 1100 }, "S-1-5-21-2659826518-2396530539-1407762326-1002": { "username":"abc", "password":"abc@456", "email":"abc@abc.de", "uid": 2222 } } }
(the JSON file is valid)
and I need to get the values out of it. But when I try to parse the JSON file an error appears:
console.log(jsonContent.S-1-5-21-2659826518-2396530539-1407762326-1001.username); ^^^^^ SyntaxError: Invalid or unexpected token
also, the
username
is underlined red from my syntax highlighter. (so there is something wrong)So I searched the internet and found nothing about it.
Here is my code:
const fs = require('fs'); const filename = "C:/Users/Jonas/Documents/Visual_Studio_Code/Node.js/json.json" contents = fs.readFileSync(filename); jsonContent = JSON.parse(contents); console.log(jsonContent.S-1-5-21-2659826518-2396530539-1407762326-1001.username);
For the case I need it, I cant edit the problematic part
S-1-5-21-2659826518-2396530539-1407762326-1001
.I also tried to set it like this:
console.log(jsonContent."S-1-5-21-2659826518-2396530539-1407762326-1001".username);
but that's ever wronger.For any more information please ask.
-
Julia - Specify arguments to input of another function
I know in Julia I can do
parse(BigFloat, x)
wherex
might be a string or the result ofreadline()
. However, what if I want to specify a precision to myBigFloat
within theparse
function?Like you can do
BigFloat(pi, precision = 50)
.I believe this can be generalized to cases where you put a function, a constructor or a type into another function and you want to specify arguments of the former one.