The result coming back from your final post is shown below. It does not contain your expected table not is it a complete HTML document. I suspect this is normally loaded using AJAX so that only a portion of the DOM is updated and then subsequent to this being processed more JavaScript is executed to load the table you seek. My suggestion to you is to use a tool such as selenium to drive your browser. For example, using Chrome:
from selenium import webdriver
from selenium.webdriver.support.select import Select
from bs4 import BeautifulSoup
from selenium.common.exceptions import StaleElementReferenceException
import time
class WaitUntilElementIsStale:
def __init__(self, *, driver=None, element=None, timeout=10):
assert driver or element
self.element = driver.find_element_by_tag_name('html') if element is None else element
self.timeout = timeout
def __enter__(self):
return None
def __exit__(self, exc_type, exc_value, exc_traceback):
if exc_type is not None:
return
start_time = time.time()
while time.time() < start_time + self.timeout:
try:
# poll the link with an arbitrary call
self.element.find_elements_by_id("doesn't-matter")
except StaleElementReferenceException:
return
time.sleep(0.1)
options = webdriver.ChromeOptions()
options.add_argument("headless") # comment out to see the browser
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
try:
driver.implicitly_wait(10) # 10 seconds is a bit of "overkill" but it doesn't hurt
driver.get('https://www.lgindiasocial.com/microsites/brand-store-web-five/locate.aspx')
with WaitUntilElementIsStale(element=driver.find_element_by_name("ddlCity")):
Select(driver.find_element_by_name("ddlState")).select_by_value('Assam')
with WaitUntilElementIsStale(element=driver.find_element_by_name("ddllocation")):
Select(driver.find_element_by_name("ddlCity")).select_by_value('Golaghat')
Select(driver.find_element_by_name("ddllocation")).select_by_value('Golaghat')
driver.find_element_by_name('btnsubmit').click()
driver.find_element_by_tag_name('table') # implicitly wait for up to 10 seconds for this element to appear
soup = BeautifulSoup(driver.page_source, "lxml")
item = soup.select_one("table")
print(item)
finally:
driver.quit()
Prints:
<table border="0" cellspacing="0" id="dladdress" rules="all" style="background-color:White;border-width:0px;width:500px;border-collapse:collapse;border:0px solid red;">
<tbody><tr>
<td style="border-width:0px;">
<div style="padding:5px;text-align: left;width: 85%;">
<div style="padding-top:10px; padding-bottom:5px; color:#d80546; ">LG BRAND STORE - BRAHMAPUTRA ELECTRONICS</div>
<span id="dladdress_ctl02_divaddress" style="font-weight:bold; padding-bottom:10px;">Complete Address : </span>
<span style="text-transform:capitalize">g.f. road, near das & co., golaghat, assam</span><br/>
<span id="dladdress_ctl02_divcontact" style="font-weight:bold; padding-bottom:10px;">Contact Person :</span>
<span style="text-transform:capitalize;">pravin kankani<br/>
<span id="dladdress_ctl02_divphone" style="font-weight:bold; padding-bottom:10px;">Contact No. :</span> <span id="dladdress_ctl02_lblcontact">9954305770 , </span><br/>
<span id="dladdress_ctl02_divemail" style="font-weight:bold; padding-bottom:10px;"> Email ID:</span> brahmaputralgshoppe@yahoo.com<br/></span>
</div>
</td>
</tr>
</tbody></table>
UPDATE:
I see that you have updated your question. I assume that you have done a network trace to see what the subsequent AJAX POST request is being used to get the final results. You are very dependent on the internals of the website's application not changing, but I suppose to the extent that they remain constant your code will work.
I have updated my solution to not have to arbitrarily wait 1 second each time a selection is made in a dropdown before attempting to make a selection in the next dropdown. After a selection is made, for example, in the state dropdown, the current city dropdown is recreated (and the original one becomes "stale"). The new code just repeatedly waits for the current city dropdown to become stale before looking for the new one. Thus, there should be little waste of time.
The second change is simply to load the complete HTML into Beautiful Soup as you do.
Of course, this code is dependent on the user interface not changing. But it is rather apparent when the user interface does change and this code is easily adapted to such changes.
Results of Your Original Post Request:
3256|updatePanel|UpdatePanel1|
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center">Locate nearest LG Brand Store</div>
<div class="col-md-12 text-center">
<div class="row">
<div class="col-md-3"><select name="ddlState" onchange="javascript:setTimeout('__doPostBack(\'ddlState\',\'\')', 0)" id="ddlState" class="select">
<option selected="selected" value="Select State">Select State</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bangalore">Bangalore</option>
<option value="Bihar">Bihar</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Delhi">Delhi</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Orissa">Orissa</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Telangana">Telangana</option>
<option value="Tripura">Tripura</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="Uttarakhand">Uttarakhand</option>
<option value="West Bengal">West Bengal</option>
</select></div>
<div class="col-md-3"><select name="ddlCity" onchange="javascript:setTimeout('__doPostBack(\'ddlCity\',\'\')', 0)" id="ddlCity" class="select">
<option selected="selected" value="Select City">Select City</option>
</select></div>
<div class="col-md-3"><select name="ddllocation" id="ddllocation" class="select">
<option selected="selected" value="Select Location">Select Location</option>
</select></div>
<div class="col-md-3"><input type="submit" name="btnsubmit" value="Submit" onclick="return validate();_gaq.push(['_trackEvent', 'LOCATE US', 'Click', 'SUBMIT']);" id="btnsubmit" class="submit" /></div>
</div>
</div>
<div class="col-md-12 text-center mt-5">
<div class="col-md-12 text-center">
<div class="row">
<div class="col-md-6">
<div id="map" style="display:none;height: 360px; width:100%;margin-left:10px;border:1px solid #cccccc;"></div>
</div>
<div class="col-md-6"><!----------------------------MAP START---------------------------------->
<div id="divgrid" style="display:block;background-color:White;width:100%;height:360px;border:1px solid #cccccc;overflow-x:hidden;overflow-y:auto;">
<div>
</div>
</div>
</div>
</div>
<!----------------------------MAP END---------------------------------->
</div>
</div>
</div>
</div>
|0|hiddenField|__EVENTTARGET||0|hiddenField|__EVENTARGUMENT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XeCZcengG4dgFTVwW32wA7WjbpUGZw1/YKENhiesda8ZP/nrFNmXDFqMHNm5Oe059jCxk+GpsKRRK3eN5nnXTez3uXx+XdJNrgVBR+gufhsAW/Z7N4b1SKpBnKa3t7O7KBUhrn60PnluMlmrAq6yppcJ6SSyBLVbJPTZLORUKmp2ha3FUSRBl/Ei8bx1FdJXFFcWP0k/c+vWmsBpiyvkD6azYWadVRcL6OdTb9iBl2BP4qktMGxQj7xtFbP8Jk3iAbf/CULABw6wUrl+JdCITSNPfypfsM+MWFKEb1M4a+PGtRcYBIcWe7hmzyjau9j1XCxZJuUNMgiwQYv/Zdl8pMzKEFOM9Rt9oUQvkOnOVLggqqK+rLhiSbwZfI7HRvoC3eLdta9NY7D+6PNrwGkfOnnjCeyWTRMHD61rA2tt/bHOJNr+HEgIMimYgsfMW6q244E/OLDDLPCYcBvHpDsJilHJCY9olAm6+j/8jAyYzHvDzUJSDpf6PImydtv7er2gvryRRBAeImlSLasgP+3ujnrfgG3DA9L6PoV2P9Ft6INQGhrHIwmxtCUnl7THLHCLcqFGW6mG4Sn5CJTp2BnqtM0xFecL/ytDHA+xYHnEs4ky|8|hiddenField|__VIEWSTATEGENERATOR|06ED1D24|0|hiddenField|__VIEWSTATEENCRYPTED||0|asyncPostBackControlIDs|||0|postBackControlIDs|||13|updatePanelIDs||tUpdatePanel1|0|childUpdatePanelIDs|||12|panelsToRefreshIDs||UpdatePanel1|2|asyncPostBackTimeout||90|11|formAction||locate.aspx|14|scriptBlock|ScriptContentNoTags|var player=[];|13|scriptStartupBlock|ScriptContentNoTags|initialize();|