Python Forum
Python requests to loop over the list and click button
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python requests to loop over the list and click button
#6
hi, i got it solved this is the solution,

import requests
from bs4 import BeautifulSoup

url = "http://upreraportal.cloudapp.net/View_projects.aspx"
response = requests.get(url).text
soup = BeautifulSoup(response,"html.parser")

VIEWSTATE = soup.select("#__VIEWSTATE")[0]['value']
EVENTVALIDATION = soup.select("#__EVENTVALIDATION")[0]['value']

for title in soup.select("#ContentPlaceHolder1_DdlprojectDistrict [value]")[:-1]:
    search_item = title.text
    # print(search_item)

    headers= {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
              'Content-Type':'application/x-www-form-urlencoded',
              'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'}

    formfields = {'__VIEWSTATE':VIEWSTATE,  #Put the value in this variable
                '__VIEWSTATEGENERATOR':'4F1A7E70',
                '__EVENTVALIDATION':EVENTVALIDATION, #Put the value in this variable
                'ctl00$ContentPlaceHolder1$DdlprojectDistrict':search_item,
                'ctl00$ContentPlaceHolder1$txtProject':'',
                'ctl00$ContentPlaceHolder1$btnSearch':'Search'}

    #here in form details check agra , i am able to scrape one city only,
    # how to loop for all cities
    res = requests.post(url, data=formfields, headers=headers).text
    soup = BeautifulSoup(res, "html.parser")

    get_list  = soup.find_all('option')   #gets list of all <option> tag
    for element in get_list :
        cities = element["value"]
        #final.append(cities)
        #print(final)

    get_details = soup.find_all("table", attrs={"id":"ContentPlaceHolder1_GridView1"})

    for details in get_details:
        text = details.find_all("tr")[1:]
        for tds in text:
            td = tds.find_all("td")[1]
            rera = td.find_all("span")
            rnumber = ""
            for num in rera:
                rnumber = num.text
                print(rnumber)
By this code i can scrape this website completely.
Reply


Messages In This Thread
RE: Python requests to loop over the list and click button - by Prince_Bhatia - Oct-27-2017, 01:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cant click button by script at page michael1834 1 1,077 Dec-08-2023, 04:44 PM
Last Post: SpongeB0B
  Click on a button on web page using Selenium Pavel_47 7 4,727 Jan-05-2023, 04:20 AM
Last Post: ellapurnellrt
  POST requests - different requests return the same response Default_001 3 1,957 Mar-10-2022, 11:26 PM
Last Post: Default_001
  Show HTML in Python application and handle click SamHobbs 2 2,740 Sep-28-2021, 06:27 PM
Last Post: SamHobbs
  button click error rafarangel 2 3,136 Feb-11-2021, 08:19 PM
Last Post: buran
  Problem with logging in on website - python w/ requests GoldeNx 6 5,346 Sep-25-2020, 10:52 AM
Last Post: snippsat
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 3,841 Jun-07-2020, 04:42 PM
Last Post: samlee916
  How to click facebook message button JanelleGuthrie 2 2,421 May-14-2020, 06:02 PM
Last Post: Larz60+
  How to perform a successful login(signin) through Requests in Python Kalet 1 2,356 Apr-24-2020, 01:44 AM
Last Post: Larz60+
  Contact form button click action Man_from_India 1 2,803 Feb-01-2020, 06:21 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020