How to search by name attribute? - beautifulsoup

I'm trying to find an input element <input id="telephone" name="telephone">. I tried soup.find('input', name='telephone') and didn't find it. However soup.find('input', id='telephone') works fine. I think the problem is that 'name' has two meanings, the name of the tag and the name attribute. So, how can I search by the name attribute?
Obviously in my example I can search by the id attribute, but that's not there in my actual predicament.

You can also use the attrs parameter. For example:
soup.find('input', attrs={'name': 'telephone'})
or, more simply in your case:
soup.find('input', {'name': 'telephone'})
(See https://www.crummy.com/software/BeautifulSoup/bs4/doc/#the-keyword-arguments)
You don't have to pass the tag name ('input' in your case) - you can just search by attributes alone - but I've included it to match the details of your question.
Hope this is helpful.

Im not sure that you wrote.
soup.find('input', name='telephone');
Would you try to use this?
soup.find('input[name="telephone"]');
Hope it works.

Related

Inputs for searching (form:select)

Is it possible to use Search like this in order to refer a specific {name} provided by an input? I want to create an input form like: <form:select items="${cars}" path="car" itemLabel="type" itemValue="id"/>. This is my controller mapping: #GetMapping("/searchby/{name}"). Thanks!
it should be possible but not recommended, from what i know using url parameters (domain.com/page?value=theValue) is better

Grails trouble saving object id

id is present in the params but does not save to the db. for example
[book.id:1, comments: good]
comments will save to db but book.id does not.
I need to figure out how to save params.book.id into the db column BOOK_ID that was created from the hasmany/belongsTo relationship.
By default value attribute of each element will be the result of a toString() call on each element. Setting it as optionKey allows the value to be a bean property of each element in the list.
Kindly change the select to
<g:form action="review">
<g:select name="book.id"
from="${item.Book.list()}"
value="${book?.id}"
/>
<g:textField name="bookreview" value="${params?.bookreview}" /><br>
kindly refer the below link
Grail example with optionkey
You have overwritten toString, therefore your books are always rendered by name and not id. If you remove your toString() method you will see the expected results.
If you want your select box work with the name, just add optionValue="name".
Well, it seems that I had misspelled a crucial parameter inside my domain. So the domain was expecting x and it was getting y. Thus the id was always null. It took me a while to spot it, and I was perplexed because I had previously successfully implemented ids in another project. Grails has some jira issues also that make one consider other possibilities, but this time it was my mistake.

bazaar auto tag

I want to use the automatic_tag_name hook to automatic create tag name without the need of manually typing
I tried to write it like it : automatic_tag_name(branch name,10)= "GIL"
Is it the correct syntax? (i found iittle information on it in the documents)
Is it possible to create tag name from a file? this file will contains only the tag name
See this example pahe here:
http://doc.bazaar.canonical.com/latest/en/user-guide/hooks.html
SO correct call should be:
def post_push_autotag(push_result):
automatic_tag_name(push_result.new_revno)
branch.Branch.hooks.install_named_hook('post_push_autotag', post_push_autotag, 'My autotag')

Multiple Zend Multicheckbox same name

I have a Zend_Form with multiple Multicheckbox element, the thing that I want is to give them all the same name: categories[].
When I add multiple elements like this:
$this->createElement('multiCheckbox', 'categories[]')
->setLabel('Category 1')
->addMultiOption(1, 'Subcat1')
$this->createElement('multiCheckbox', 'categories[]')
->setLabel('Category 2')
->addMultiOption(2, 'Subcat2')
etc...
Only the Category 2 checkboxes are displayed.
Seems that Zend has the element name as leading. Currently I workaround this with different element names but this isn't really workable at all.
How can I solve this?
that's not how you use multiCheckbox,
use
$multicheckbox->addMultiOptions($zone);
see here a similar example addmultioption array problem in Zend
Ended splitting them up in separate groups.

Creating tags on posts RAILS

I am making something that's like that autocomplete tags field for the posts on stackoverflow.com
I want to make it so that when you make a blog post, you can tag it with words in a database, similar to SO.
For the posts, it belongs_to_and_has_many tags
For the tags, it belongs_to_and_has_many posts
However it is a problem for me to do it on the same page because #post would be nil.
How can I implement this?
(If someone can give me the code for the stackoverflow ask question page that would be AWESOME)
I think the problem here is that it seems like you are asking two different questions. Please correct me if I'm wrong on this.
The first question is how you would implement the autocomplete feature to allow users to easily select from a pre-populated list of tags. To answer this, you might refer to spncrgr's answer above.
The second question is how to deal with associating these retrieved tags to the current post. For this you can add additional javascript functionality to your autocomplete solution. When a user selects which tag they want from the autocomplete field, you can do like StackOverflow does and add the tag to a list of tags in a single text field. These can be either space or comma delimited. When you submit the form to create the new post, you can parse this field into it's separate tags:
tags = params[:tags].split(' ')
You can then associate these tags to the model in the Post#create action.
This may not help you at all (or you may have already seen it), but here's a link to a Railscasts' episode on auto-complete:
http://railscasts.com/episodes/102-auto-complete-association
I know it helped me when trying to do something similar.
HTH
It looks for me like you want to generate tags automatically.
You could create
class Post
before_save :create_tags
private
def create_tags
# get your tags somehow
self.tags << Tag.new(:text=>"...")
end
end
method in models/post.rb and build them there.
If you want to search among existing tags for your auto-suggest, you should have it match from Tag.all, as that won't be nil, just as you would collect a group of objects in a select drop down. Not sure about the code for auto-complete, but the tags should be in the Tag table.