Filling with no 'name' attribute in MechanicalSoup












1















I am quite new to webscrapping so I am having a trouble automatically filling in forms. Below is the relevant python code and html source code of the webpage.
So, what I am trying to do is to fill forms that do not have 'name' attribute but have 'class' attribute. But python gives me an error.



brw = ms.StatefulBrowser()
brw.open("http://www.krisha.kz")
brw.select_form('form[action="/prodazha/kvartiry/"]')
brw.get_current_form().print_summary()
brw["category-type"]="rent"
brw.submit_selected()
brw.get_url()





<form id="search-form" action="/prodazha/kvartiry/" method="get">
<div class="search-block-inputs">
<div class="search-block-form search-block-category">
<div class="search-element-wrap">
<div class="element-select">
<select class="category-type">
<option data-alias="prodazha" value="sell" selected>Купить</option>
<option data-alias="arenda" value="rent" >Снять</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>

<div class="search-element-wrap categories-for-sell">
<div class="element-select">
<select>
<option value="" data-alias="kvartiry" selected="selected">квартиру</option>
<option value="" data-alias="doma">дом</option>
<option value="" data-alias="dachi">дачу</option>
<option value="" data-alias="uchastkov">участок</option>
<option value="" data-alias="ofisa">офис</option>
<option value="" data-alias="pomeshhenija">помещение</option>
<option value="" data-alias="zdanija">здание</option>
<option value="" data-alias="magazina">магазин, бутик</option>
<option value="" data-alias="prombazy">промбазу, склад</option>
<option value="" data-alias="prochej-nedvizhimosti">прочее</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>





Python gives me an error "LinkNotFoundError: No valid element named category-type".
Can you please help me to figure out how to fill with no 'name' attributes?
Also, there are some items that do not have attributes at all, so how to deal with them?



Thank you in advance!










share|improve this question























  • Possible duplicate of Using mechanicalsoup to set value of form element w/o a name

    – Matthieu Moy
    Jan 2 at 9:38
















1















I am quite new to webscrapping so I am having a trouble automatically filling in forms. Below is the relevant python code and html source code of the webpage.
So, what I am trying to do is to fill forms that do not have 'name' attribute but have 'class' attribute. But python gives me an error.



brw = ms.StatefulBrowser()
brw.open("http://www.krisha.kz")
brw.select_form('form[action="/prodazha/kvartiry/"]')
brw.get_current_form().print_summary()
brw["category-type"]="rent"
brw.submit_selected()
brw.get_url()





<form id="search-form" action="/prodazha/kvartiry/" method="get">
<div class="search-block-inputs">
<div class="search-block-form search-block-category">
<div class="search-element-wrap">
<div class="element-select">
<select class="category-type">
<option data-alias="prodazha" value="sell" selected>Купить</option>
<option data-alias="arenda" value="rent" >Снять</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>

<div class="search-element-wrap categories-for-sell">
<div class="element-select">
<select>
<option value="" data-alias="kvartiry" selected="selected">квартиру</option>
<option value="" data-alias="doma">дом</option>
<option value="" data-alias="dachi">дачу</option>
<option value="" data-alias="uchastkov">участок</option>
<option value="" data-alias="ofisa">офис</option>
<option value="" data-alias="pomeshhenija">помещение</option>
<option value="" data-alias="zdanija">здание</option>
<option value="" data-alias="magazina">магазин, бутик</option>
<option value="" data-alias="prombazy">промбазу, склад</option>
<option value="" data-alias="prochej-nedvizhimosti">прочее</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>





Python gives me an error "LinkNotFoundError: No valid element named category-type".
Can you please help me to figure out how to fill with no 'name' attributes?
Also, there are some items that do not have attributes at all, so how to deal with them?



Thank you in advance!










share|improve this question























  • Possible duplicate of Using mechanicalsoup to set value of form element w/o a name

    – Matthieu Moy
    Jan 2 at 9:38














1












1








1


1






I am quite new to webscrapping so I am having a trouble automatically filling in forms. Below is the relevant python code and html source code of the webpage.
So, what I am trying to do is to fill forms that do not have 'name' attribute but have 'class' attribute. But python gives me an error.



brw = ms.StatefulBrowser()
brw.open("http://www.krisha.kz")
brw.select_form('form[action="/prodazha/kvartiry/"]')
brw.get_current_form().print_summary()
brw["category-type"]="rent"
brw.submit_selected()
brw.get_url()





<form id="search-form" action="/prodazha/kvartiry/" method="get">
<div class="search-block-inputs">
<div class="search-block-form search-block-category">
<div class="search-element-wrap">
<div class="element-select">
<select class="category-type">
<option data-alias="prodazha" value="sell" selected>Купить</option>
<option data-alias="arenda" value="rent" >Снять</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>

<div class="search-element-wrap categories-for-sell">
<div class="element-select">
<select>
<option value="" data-alias="kvartiry" selected="selected">квартиру</option>
<option value="" data-alias="doma">дом</option>
<option value="" data-alias="dachi">дачу</option>
<option value="" data-alias="uchastkov">участок</option>
<option value="" data-alias="ofisa">офис</option>
<option value="" data-alias="pomeshhenija">помещение</option>
<option value="" data-alias="zdanija">здание</option>
<option value="" data-alias="magazina">магазин, бутик</option>
<option value="" data-alias="prombazy">промбазу, склад</option>
<option value="" data-alias="prochej-nedvizhimosti">прочее</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>





Python gives me an error "LinkNotFoundError: No valid element named category-type".
Can you please help me to figure out how to fill with no 'name' attributes?
Also, there are some items that do not have attributes at all, so how to deal with them?



Thank you in advance!










share|improve this question














I am quite new to webscrapping so I am having a trouble automatically filling in forms. Below is the relevant python code and html source code of the webpage.
So, what I am trying to do is to fill forms that do not have 'name' attribute but have 'class' attribute. But python gives me an error.



brw = ms.StatefulBrowser()
brw.open("http://www.krisha.kz")
brw.select_form('form[action="/prodazha/kvartiry/"]')
brw.get_current_form().print_summary()
brw["category-type"]="rent"
brw.submit_selected()
brw.get_url()





<form id="search-form" action="/prodazha/kvartiry/" method="get">
<div class="search-block-inputs">
<div class="search-block-form search-block-category">
<div class="search-element-wrap">
<div class="element-select">
<select class="category-type">
<option data-alias="prodazha" value="sell" selected>Купить</option>
<option data-alias="arenda" value="rent" >Снять</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>

<div class="search-element-wrap categories-for-sell">
<div class="element-select">
<select>
<option value="" data-alias="kvartiry" selected="selected">квартиру</option>
<option value="" data-alias="doma">дом</option>
<option value="" data-alias="dachi">дачу</option>
<option value="" data-alias="uchastkov">участок</option>
<option value="" data-alias="ofisa">офис</option>
<option value="" data-alias="pomeshhenija">помещение</option>
<option value="" data-alias="zdanija">здание</option>
<option value="" data-alias="magazina">магазин, бутик</option>
<option value="" data-alias="prombazy">промбазу, склад</option>
<option value="" data-alias="prochej-nedvizhimosti">прочее</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>





Python gives me an error "LinkNotFoundError: No valid element named category-type".
Can you please help me to figure out how to fill with no 'name' attributes?
Also, there are some items that do not have attributes at all, so how to deal with them?



Thank you in advance!






<form id="search-form" action="/prodazha/kvartiry/" method="get">
<div class="search-block-inputs">
<div class="search-block-form search-block-category">
<div class="search-element-wrap">
<div class="element-select">
<select class="category-type">
<option data-alias="prodazha" value="sell" selected>Купить</option>
<option data-alias="arenda" value="rent" >Снять</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>

<div class="search-element-wrap categories-for-sell">
<div class="element-select">
<select>
<option value="" data-alias="kvartiry" selected="selected">квартиру</option>
<option value="" data-alias="doma">дом</option>
<option value="" data-alias="dachi">дачу</option>
<option value="" data-alias="uchastkov">участок</option>
<option value="" data-alias="ofisa">офис</option>
<option value="" data-alias="pomeshhenija">помещение</option>
<option value="" data-alias="zdanija">здание</option>
<option value="" data-alias="magazina">магазин, бутик</option>
<option value="" data-alias="prombazy">промбазу, склад</option>
<option value="" data-alias="prochej-nedvizhimosti">прочее</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>





<form id="search-form" action="/prodazha/kvartiry/" method="get">
<div class="search-block-inputs">
<div class="search-block-form search-block-category">
<div class="search-element-wrap">
<div class="element-select">
<select class="category-type">
<option data-alias="prodazha" value="sell" selected>Купить</option>
<option data-alias="arenda" value="rent" >Снять</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>

<div class="search-element-wrap categories-for-sell">
<div class="element-select">
<select>
<option value="" data-alias="kvartiry" selected="selected">квартиру</option>
<option value="" data-alias="doma">дом</option>
<option value="" data-alias="dachi">дачу</option>
<option value="" data-alias="uchastkov">участок</option>
<option value="" data-alias="ofisa">офис</option>
<option value="" data-alias="pomeshhenija">помещение</option>
<option value="" data-alias="zdanija">здание</option>
<option value="" data-alias="magazina">магазин, бутик</option>
<option value="" data-alias="prombazy">промбазу, склад</option>
<option value="" data-alias="prochej-nedvizhimosti">прочее</option>
</select>
<svg role="img" class="icon icon-svg icon-arrow-down"><use xlink:href="#icon-arrow-down"></use></svg>
</div>
</div>






python beautifulsoup mechanicalsoup






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 9:07









mansismansis

61




61













  • Possible duplicate of Using mechanicalsoup to set value of form element w/o a name

    – Matthieu Moy
    Jan 2 at 9:38



















  • Possible duplicate of Using mechanicalsoup to set value of form element w/o a name

    – Matthieu Moy
    Jan 2 at 9:38

















Possible duplicate of Using mechanicalsoup to set value of form element w/o a name

– Matthieu Moy
Jan 2 at 9:38





Possible duplicate of Using mechanicalsoup to set value of form element w/o a name

– Matthieu Moy
Jan 2 at 9:38












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003663%2ffilling-select-with-no-name-attribute-in-mechanicalsoup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003663%2ffilling-select-with-no-name-attribute-in-mechanicalsoup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter