variable in BeautifulSoup find() method is not working - python-3.x

I am using BeautifulSoup in python3.6. I am not getting an error while using a string as a parameter in the find method.
bs.find('div',attrs={'class' : 'ptag'}).text
but i am getting error while using variable instead of string directly.
bs.find('div',{'class' : ptagclass})
Error:
data=(bs.find('div',{'class' : ptagclass}).text)
AttributeError: 'NoneType' object has no attribute 'text'

The problem relies upon in the way you are trying to find the parameter, try replacing
bs.find('div',{'class' : ptagclass})
with
bs.find('div',{'class' : "ptagclass"}) this should solve the issue.
Hope this helps

Related

Module Object is Not callable for

module object is not callable, how 2 fix
For some reason I'm getting a module object is not callable error on this code. I don't really get why? Whats going on and how do I fix it? :(

Python xml.etree.ElementTree getroot() doesnt work [duplicate]

I was using parse function to modify a xml and it worked but I tried to use .fromstring and it showed an error
AttributeError: 'Element' object has no attribute 'getroot'
here is the part of code.
AttributeError: 'Element' object has no attribute 'getroot'
This is because the fromstring method returns the root object already. SO whatever your var that stores the information form the "fromstring()" method is, that var is the root.

No attribute error passing broadcast variable from PySpark to Java function

I have a java class registered in PySpark, and Im trying to pass a Broadcast variable from PySpark to a method in this class. Like so:
from py4j.java_gateway import java_import
java_import(spark.sparkContext._jvm, "net.a.b.c.MyClass")
myPythonGateway = spark.sparkContext._jvm.MyClass()
with open("tests/fixtures/file.txt", "rb") as binary_file:
data = spark.sparkContext.broadcast(binary_file.read())
myPythonGateway.setData(data)
But this is throwing:
AttributeError: 'Broadcast' object has no attribute '_get_object_id'
However, if I pass the byte[] directly, without wrapping it in broadcast(), it works fine. But I need this variable to be broadcast, as it will be used repeatedly.
According to the py4j docs, the above error will be thrown if you try to pass a Python collection to a method that expects a Java collection. The docs give the following solution:
You can explicitly convert Python collections using one of the following converter located in the py4j.java_collections module: SetConverter, MapConverter, ListConverter.
An example is provided there also.
Presumably, this error is occurring when py4j tries to convert the value attribute of the Broadcast object, so converting this may fix the problem e.g.
converted_data = ListConverter().convert(binary_file.read(),spark.sparkContext._jvm._gateway_client)
broadcast_data = spark.sparkContext.broadcast(converted_data)
myPythonGateway.setData(broadcast_data)

Error missging property when $ref is used as part of an url in groovy script

I have a httpBUilder url which needs to be format as below:
"https://graph.microsoft.com/v1.0/groups/60a10121-9e1d-xxxx-xxxxx/members/$ref"
This format url is used by MS Graph API to reference a user
When using in in Groovy I get an exception as below
"groovy.lang.MissingPropertyException: No such property: ref for class: Script689
at Script689.run(Script689.groovy:18)"
I guess that $ is used for property injection in groovy.
How can I solved it to get my url correct ?
regards
Just change the $ref to \$ref, it will work.

If Statement in Template

I want to create my own template and my code is:
#{if _arg.status.equals(models.Status.FINISHED)}
#{doBody /}
#{/if}
When I pass an object reference to my tag its saying its null. If I call in my template its working as described in the docs:
${_arg.status}
The error message is:
Template execution error
Execution error occured in template
/app/views/tags/isNotFinished.html. Exception raised was
NullPointerException : Cannot get property 'status' on null object.
I am not getting any null pointer exception. What I am doing wrong here?
Thanks for your help.
It seems like _arg is not found in the scope you're working with. This seems to indicate you get arg implicitly in the tag. You might try omitting the _arg. from the tag.
I am not getting it really. But today I tried again with _arg and its working now as excpected. It can be closed now.

Resources