0

Im very new to python and web scraping etc but Im trying to learn while I read but Im stuck now. I have managed to use python and BeautifulSoup to grab a kinda web form from a page where theres alot of checkboxes. What Im trying to do is change some of these checkboxes from checked to unchecked or the other way around. But dont know where to really go from here.

The output from a checkbox thats checked looks like this:

    <div class="checkbox">
     <label>
      <input checked="checked" name="Permissions" type="checkbox" value="SeeDetailedInformation"/>
     </label>
    </div>

The output from a checkbox thats not checked looks like this:

    <div class="checkbox">
     <label>
      <input name="Permissions" type="checkbox" value="AdjustCounters"/>
     </label>
    </div>

Question is how do I change the checkbox to not beeing check or checked if thats what I want using requests.post or any other good method of changing this.

Any help with either code I can try or pointers to where I should read up on this is much appriciated. I have read abit about selenium and webdriver but dont think this will do it for me as I have 500+ pages/forms on different urls to change. (Going from url to url isnt a problem, I just need some input on have to change the checkbox)

3
  • The checkbox doesn't exist, only a description of it. If you want to create a query, don't include the parameter if it should be unchecked, or include it if it should be checked, e.g. Permissions=AdjustCounters Commented Oct 21, 2019 at 20:13
  • @PeterWood You have an example of how that query could be written? Im all new to this Commented Oct 21, 2019 at 20:20
  • stackoverflow.com/a/12757144/1084416 Commented Oct 21, 2019 at 22:34

1 Answer 1

0

You should look into selenium and its use as a driver for your browser. Beautifulsoup is great for parsing documents, and I'm not familiar with it's usage in form completion, but selenium can certainly do what you're looking for. I would check out this snippet of code too:

checkboxes = webdriver.find_elements_by_class('checkbox')
for i in range(len(checkboxes)):
    checkbox = checkboxes[i]
    if ((values[i] and not checkbox.is_selected()) or (not values[i] and checkbox.is_selected())):
        checkbox.click()

where values is a list of booleans representing whether each checkbox should be selected or not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.