Nokogiri parsing with xpath returns empty string - ruby-on-rails-4

I have the following HTML:
<div>
<table>
<tr>
<td>
<div class="w135">
<div style="float: left; padding-right: 10px;" class="imageThumbnail playerDiv">
<a href="/sport/tennis/2014/10/djokovic-through-wozniacki-out-china-open-2014101114115427766.html" id="ctl00_ctl00_DataList1_ctl00_Thumbnail1_lnkImage10" target="_parent">
<img src="/mritems/imagecache/89/135/mritems/images/2014/10/1/2014101114447491734_20.jpg" id="ctl00_ctl00_DataList1_ctl00_Thumbnail1_imgSmall10" border="0" class="imageThumbnail">
</a>
</div>
</div>
</td>
</tr>
</table>
</div>
When i attempt the rake, i get the error:
NoMethodError: undefined method `at_css' for ["id","ctl00_cphBody_ctl01_DataList1_ctl00_Thumbnail1_Layout17"]:Array
This is the code:
#request = HTTParty.get(url)
#html = Nokogiri::HTML(#request.body)
#html.css(".w135")[0].map do |item|
url = item.at_css("div.playerDiv a")
puts url.inspect
end
I'm really not sure what the issue is and have been trying to fix this for a while. The error occurs on this line url = item.at_css("div.playerDiv a")
Any suggestion is appreciated!
Thanks

I'd do it using something like:
require 'nokogiri'
doc = Nokogiri::HTML(<<EOT)
<div>
<table>
<tr>
<td>
<div class="w135">
<div style="float: left; padding-right: 10px;" class="imageThumbnail playerDiv">
<a href="/sport/tennis/2014/10/djokovic-through-wozniacki-out-china-open-2014101114115427766.html" id="ctl00_ctl00_DataList1_ctl00_Thumbnail1_lnkImage10" target="_parent">
<img src="/mritems/imagecache/89/135/mritems/images/2014/10/1/2014101114447491734_20.jpg" id="ctl00_ctl00_DataList1_ctl00_Thumbnail1_imgSmall10" border="0" class="imageThumbnail">
</a>
</div>
</div>
</td>
</tr>
</table>
</div>
EOT
puts doc.search('.w135 div.playerDiv a').map(&:inspect)
Which outputs:
# >> #<Nokogiri::XML::Element:0x3ff0918b132c name="a" attributes=[#<Nokogiri::XML::Attr:0x3ff0918b1250 name="href" value="/sport/tennis/2014/10/djokovic-through-wozniacki-out-china-open-2014101114115427766.html">, #<Nokogiri::XML::Attr:0x3ff0918b123c name="id" value="ctl00_ctl00_DataList1_ctl00_Thumbnail1_lnkImage10">, #<Nokogiri::XML::Attr:0x3ff0918b1228 name="target" value="_parent">] children=[#<Nokogiri::XML::Text:0x3ff0918a5b6c "\n ">, #<Nokogiri::XML::Element:0x3ff0918a5360 name="img" attributes=[#<Nokogiri::XML::Attr:0x3ff0918a4d20 name="src" value="/mritems/imagecache/89/135/mritems/images/2014/10/1/2014101114447491734_20.jpg">, #<Nokogiri::XML::Attr:0x3ff0918a4cbc name="id" value="ctl00_ctl00_DataList1_ctl00_Thumbnail1_imgSmall10">, #<Nokogiri::XML::Attr:0x3ff0918a4b90 name="border" value="0">, #<Nokogiri::XML::Attr:0x3ff0918a4a28 name="class" value="imageThumbnail">]>, #<Nokogiri::XML::Text:0x3ff091871920 "\n ">]>
If you're trying to access the "href" parameter, instead of using inspect, use:
puts doc.search('.w135 div.playerDiv a').map{ |n| n['href'] }
# >> /sport/tennis/2014/10/djokovic-through-wozniacki-out-china-open-2014101114115427766.html

Related

how to get text out of span in python using scrapy?

<div id="eventInfoContainer">
<table>
<tbody><tr>
<td class="verticalTop">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2475575566915822";
/* listing page */
google_ad_slot = "4647770957";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><ins id="aswift_0_expand" style="display:inline-table;border:none;height:600px;margin:0;padding:0;position:relative;visibility:visible;width:160px;background-color:transparent;"><ins id="aswift_0_anchor" style="display:block;border:none;height:600px;margin:0;padding:0;position:relative;visibility:visible;width:160px;background-color:transparent;"><iframe width="160" height="600" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&&s.handlers,h=H&&H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&&d&&(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;width:160px;height:600px;"></iframe></ins></ins>
</td>
<td class="spacer30w"></td>
<td class="verticalTop">
<span id="eventNameHeader">The Future of Medicine, Health Care and Biological Studies</span>
<br>
<br>
<span id="smallerHeading">Conference</span>
<br>
<br>
<span id="eventDate">16th to 17th October 2017</span>
<br>
<span id="eventCountry">Rockville, Maryland, United States of America</span>
<br>
<br>
<span id="eventWebsite">
<span id="smallerHeading">Website: </span>
http://rais.education/the-future-of-medicine-health-care-and-biological-studies/
</span>
<br>
<span id="eventContactPerson"><span id="smallerHeading">Contact person: </span>Eduard David</span>
<br>
<br>
<span id="eventDescription">We gladly invite you to attend the International Conference The Future of Medicine, Health Care and Biological Studies which will be held at Johns Hopkins University, just 20 miles away from Washington DC. </span>
<br>
<br>
<span id="eventOrganiser"><span style="font-weight: bold; color: #696969;">Organized by: </span>Research Association for Interdisciplinary Studies (RAIS)</span> <br><span id="eventDeadline"><span style="font-weight: bold; color: #696969;">Deadline for abstracts/proposals: </span>21st August 2017</span> <br>
<br>
Check the event website for more details.
<br>
<br>
<br>
<br>
<br>
<br>
<table>
<tbody><tr>
<td class="verticalMiddle">
<form><input type="button" value="Back" onclick="history.go(-1); return true;"></form>
</td>
<td class="spacer15w"></td>
<td class="verticalMiddle">
<a title="Share this conference on Facebook" href="http://www.facebook.com/sharer.php?
s=100
&p[url]=http://www.conferencealerts.com/show-event?id=187457 &p[title]=The Future of Medicine, Health Care and Biological Studies &p[summary]=We gladly invite you to attend the International Conference The Future of Medicine, Health Care and Biological Studies which will be held at Johns Hopkins University, just 20 miles away from Washington DC. " target="_blank" class="fb_share_link">Share on Facebook</a>
</td>
<td class="spacer15w"></td>
<td>
<img src="http://www.google.com/calendar/images/ext/gc_button6.gif" border="0" align="left">
</td>
</tr>
<tr><td class="spacer5"></td></tr>
<tr>
<td colspan="5">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2475575566915822";
/* show event under content */
google_ad_slot = "8943315143";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><ins id="aswift_1_expand" style="display:inline-table;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent;"><ins id="aswift_1_anchor" style="display:block;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent;"><iframe width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&&s.handlers,h=H&&H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&&d&&(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;width:300px;height:250px;"></iframe></ins></ins>
</td>
</tr>
</tbody></table>
<br>
</td>
</tr>
</tbody></table>
</div>
How to get text "The Future of Medicine, Health Care and Biological Studies" from above code in python using scrapy?
I tried this code
response.css('div.eventInfoContainer table tbody tr td:nth-child(3) span::text').extract()
But o/p getting like this "[]"
As the span element that contains the required information has an id attribute (which should be unique), this should suffice:
text = response.css('span#eventNameHeader::text').extract_first()
EDIT:
Using XPath, it's similar:
text = response.xpath('//span[#id="eventNameHeader"]/text()').extract_first()

BeautifulSoup My extracted data from HTML table does not print out in the same table format. Can i keep the table format

I have a HTML Test Report file with a list of test cases. Each test case is in a row in an HTML table.
I have managed to get the test cases out from the table for each row.
When i write this out into my email code it does not write it out as a table format like in the HTML. I would like to keep the grid lines for the rows and columns so it displays nicely as a table.
My method to extract the data is:
def extract_testcases_from_report_htmltestrunner():
filename = (r"E:\test_runners project\selenium_regression_test\TestReport\ClearCore_Automated_GUI_Regression_Project_TestReport.html")
html_report_part = open(filename,'r')
soup = BeautifulSoup(html_report_part, "html.parser")
for div in soup.select("#result_table tr div.testcase"):
yield div.text.strip().encode('utf-8'), div.find_next("a").text.strip().encode('utf-8')
When i write it into my email code out the output I get is:
test_000001_login_valid_user
pass
test_000002_select_a_project
pass
test_000003_verify_Lademo_CRM_DataPreview_is_present
pass
test_000004_view_data_preview_Lademo_CRM_and_test_scrollpage
pass
My desired output would be in the following format with the table lines if possible or in the same table format as it is in the HTML:
test_000001_login_valid_user pass
test_000002_select_a_project pass
test_000003_verify_Lademo_CRM_DataPreview_is_present pass
test_000004_view_data_preview_Lademo_CRM_and_test_scrollpage pass
The HTML snippet is:
<div class='heading'>
<h1>Test Report</h1>
<p class='attribute'><strong>Start Time:</strong> 2016-10-27 10:06:59</p>
<p class='attribute'><strong>Duration:</strong> 0:57:01.842000</p>
<p class='attribute'><strong>Status:</strong> Pass 93</p>
<p class='description'>Selenium - ClearCore Regression Project Automated Test</p>
</div>
<p id='show_detail_line'>Show
<a href='javascript:showCase(0)'>Summary</a>
<a href='javascript:showCase(1)'>Failed</a>
<a href='javascript:showCase(2)'>All</a>
</p>
<table id='result_table'>
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row'>
<td>Test Group/Test case</td>
<td>Count</td>
<td>Pass</td>
<td>Fail</td>
<td>Error</td>
<td>View</td>
</tr>
<tr class='passClass'>
<td>Regression_TestCase.RegressionProject_TestCase</td>
<td>47</td>
<td>47</td>
<td>0</td>
<td>0</td>
<td>Detail</td>
</tr>
<tr id='pt1.1' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000001_login_valid_user</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.1')" >
pass</a>
<div id='div_pt1.1' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.1').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.1: *** test_login_valid_user ***
test login with a valid user - Passed
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.2' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000002_select_a_project</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.2')" >
pass</a>
<div id='div_pt1.2' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.2').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.2: *** test_login_valid_user ***
test login with a valid user - Passed
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.3' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000057_run_clean_and_match_process</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.3')" >
pass</a>
<div id='div_pt1.3' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.3').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.3: *** test_login_valid_user ***
test login with a valid user - Passed
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.4' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000058_view_all_records_report_CRM_CRM2_ESCR</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.4')" >
pass</a>
<div id='div_pt1.4' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.4').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.4: *** test_login_valid_user ***
test login with a valid user - Passed
*** Test view_all_records_report - CRM, CRM2, ESCR ***
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.5' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000059_view_matches_report_CRM_CRM2_ESCR</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.5')" >
pass</a>
<div id='div_pt1.5' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.5').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.5: *** test_login_valid_user ***
test login with a valid user - Passed
*** Test view_all_records_report - CRM, CRM2, ESCR ***
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
Is it possible?
The words pass is going onto a new line. If i can separate this out into a column or by a few spaces that would be good.
The word pass is in an a tag in the HTML. The following line of code finds this. Could i put a few spaces or in another column when i extract it?:
yield div.text.strip().encode('utf-8'), div.find_next("a").text.strip().encode('utf-8')
My email message code snippet which writes it out is:
msg = MIMEText("\n ClearCore Automated GUI Project Test Report \n " + "\n" +
"".join([' - '.join(seq) for seq in extract_status_from_report_htmltestrunner()]) + "\n\n" +
'\n'.join([elem
for seq in extract_testcases_from_report_htmltestrunner()
for elem in seq]) + "\n" +
"\n Report location = : \\\storage-1\Testing\Selenium_Test_Report_Results\ClearCore\Selenium VM \n" + "\n")
My code to extract the status from the report is:
def extract_status_from_report_htmltestrunner():
filename = (
r"E:\test_runners 2 edit project\selenium_regression_test\TestReport\ClearCore_Automated_GUI_Regression_Project_TestReport.html")
html_report_part = open(filename, 'r')
soup = BeautifulSoup(html_report_part, "html.parser")
div_heading = soup.find('div', {'class': 'heading'})
p_status = div_heading.find('strong', text='Status:').parent
p_status.find(text=True, recursive=False)
print p_status.text
return p_status.text
Thanks, Riaz
from bs4 import BeautifulSoup
soup = BeautifulSoup(text, 'lxml')
trs = soup.find_all(class_='hiddenRow')
for tr in trs:
row1 = tr.find('td').get_text()
row2 = tr.find('a').get_text(strip=True)
print('{:<55}{:>5}'.format(row1, row2))
out:
test_000001_login_valid_user pass
test_000002_select_a_project pass
test_000057_run_clean_and_match_process pass
test_000058_view_all_records_report_CRM_CRM2_ESCR pass
test_000059_view_matches_report_CRM_CRM2_ESCR pass

BeautifulSoup extract data from certain columns from a table I am getting too much data out

I am trying to extract some data out of my Selenium Test Report html file.
I am getting too much data out of the table of rows and columns.
The data I would like to extract is all columns which have the class value "testcase" and there is a column below with a class value "popup_link" and the text value will say Pass or Fail.
E.g.
<td class='none'><div class='testcase'>test_000001_login_valid_user</div></td>
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.1')" >
pass</a>
I would like the text "test_000001_login_valid_user" and the text "pass"
There are lots of test cases in my report so I would like to iterate over the rows and get the test case name out and the pass or fail text.
My HTML snippet is:
<table id='result_table'>
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row'>
<td>Test Group/Test case</td>
<td>Count</td>
<td>Pass</td>
<td>Fail</td>
<td>Error</td>
<td>View</td>
</tr>
<tr class='passClass'>
<td>Regression_TestCase.RegressionProjectEdit_TestCase.RegressionProject_TestCase_Project_Edit</td>
<td>75</td>
<td>75</td>
<td>0</td>
<td>0</td>
<td>Detail</td>
</tr>
<tr id='pt1.1' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000001_login_valid_user</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.1')" >
pass</a>
<div id='div_pt1.1' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.1').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.1: *** test_login_valid_user ***
test login with a valid user - Passed
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.2' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000002_select_a_project</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.2')" >
pass</a>
<div id='div_pt1.2' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.2').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.2: *** test_login_valid_user ***
test login with a valid user - Passed
*** test_select_a_project ***
08_12_1612_08_03
Selenium_Regression_Edit_Project_Test
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='pt1.3' class='hiddenRow'>
<td class='none'><div class='testcase'>test_000003_verify_Lademo_CRM_DataPreview_is_present</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_pt1.3')" >
pass</a>
<div id='div_pt1.3' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_pt1.3').style.display = 'none' " >
[x]</a>
</div>
<pre>
pt1.3: *** test_login_valid_user ***
test login with a valid user - Passed
*** test_select_a_project ***
08_12_1612_08_03
Selenium_Regression_Edit_Project_Test
*** Test verify_Lademo_CRM_DataPreview_is_present ***
aSelenium_LADEMO_CRM_DONOTCHANGE
File
498
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
My code is:
from bs4 import BeautifulSoup
table = soup.select_one("#result_table")
for row in table.select("tr.hiddenRow"):
print(" ".join([td.text for td in row.find_all("td")]))
How can i achieve this please?
Thanks, Riaz
Check each row for both, if both exist then extract the text:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
for row in soup.select("#result_table tr"):
div, a = row.select_one("div.testcase"), row.select_one("a.popup_link")
if div and a:
print(div.text.strip(), a.text.strip())
which gives you:
(u'test_000001_login_valid_user', u'pass')
(u'test_000002_select_a_project', u'pass')
(u'test_000003_verify_Lademo_CRM_DataPreview_is_present', u'pass')
Of course if they always go together we can simplify to:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
for div in soup.select("#result_table tr div.testcase"):
print(div.text.strip(), div.find_next("a", class_="popup_link").text.strip())

uploading a file with python

I'm pretty new to programming and i'm trying to write a program that will upload a file to a website. I really don't know what I'm doing wrong. The file isn't getting uploaded. I think my issue is to do with the multipart form data but i wouldn't be surprised if i'm wrong.
import requests, os, sys
url = "myURL"
uploadFile = {'ILWinterConditions.kmz': open('C:\\Users\\JOC-001\\Documents\\GIS\\IDOT\\ILWinterConditions.kmz', 'rb')}
payload = {
'fname': 'myfname',
'lname': 'mylname',
'org': 'myorg',
'phone': 'myphone',
'email': 'myemail',
'datadescrip': 'mydatadesc',
'uploadedfile': 'C:\\Users\\JOC-001\\Documents\\GIS\\IDOT\\ILWinterConditions.kmz'
}
r = requests.post(url, verify = False, auth=('myUsername','mypassword'), files=uploadFile, data=payload)
print r.content
Below is the response I'm getting from print and the file is not being uploaded
<head>
<title>*I have censored this*</title>
<link rel="stylesheet" href="styles.css"/>
</head>
<body>
<script type="text/javascript">
// Add other extensions here if we want to allow other files to be
// uploaded. Check is not case-sensitive. Will also be checked on
// the server.
var allowedExtensions = [ "kml", "kmz", "jpg", "png", "csv" ];
var maxSize = 12 * 1024*1024;
var errorMessage = "Only .csv, .kml, .kmz, .jpg, or .png files up to 12MB are accepted!";
// Checks that the file meets our criteria. This is just for user
// convenience-- to catch problems before they attempt to do the
// upload. The file will be checked again on the server too.
function FileIsOkay() {
var fileInput = document.getElementById('uploadedFile');
// First check the file's extension
var fileName = fileInput.value;
var fileExtension = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
var extensionOK = false;
for (var i=0; i<allowedExtensions.length; ++i) {
if (fileExtension == allowedExtensions[i].toLowerCase()) {
extensionOK = true;
break;
}
}
if (! extensionOK) {
alert(errorMessage);
return false;
}
// Now check the file's size.
// Doesn't work in IE, but that's okay... it'll get checked on
// the server any way.
if (fileInput.files) {
var file = fileInput.files[0];
if (file) {
if (file.size > maxSize) {
alert(errorMessage);
return false;
}
}
}
return true;
}
</script>
<div class="title">
<img src="webdavtitle.png"/>
</div>
<form method="POST" action="uploader.php" enctype="multipart/form-data" onsubmit="return FileIsOkay();" class="fileForm">
<table class="detailsTable">
<tr>
<td class="inputLabel">First Name:</td>
<td class="inputField"><input type="text" name="fname" size="40"></td>
</tr>
<tr>
<td class="inputLabel">Last Name:</td>
<td class="inputField"><input type="text" name="lname" size="40"></td>
</tr>
<tr>
<td class="inputLabel">Organization/Agency:</td>
<td class="inputField"><input type="text" name="org" size="40"></td>
</tr>
<tr>
<td class="inputLabel">Phone (DSN or Com):</td>
<td class="inputField"><input type="text" name="phone" size="40"></td>
</tr>
<tr>
<td class="inputLabel">Email:</td>
<td class="inputField"><input type="text" name="email" size="40"></td>
</tr>
<tr>
<td class="inputLabel">Data Description:</td>
<td class="inputField"><input type="text" name="datadescrip" size="40"></td>
</tr>
<tr>
<td class="inputLabel">
Choose a .kml, .kmz, .jpg,<br/>
or .png file to upload:
</td>
<td class="inputField">
<input id="uploadedFile" name="uploadedfile" size="40" type="file"/>
</td>
</tr>
<tr>
<td></td>
<td class="inputField"><input type="submit" value="Upload File"></input></td>
</tr>
</table>
</form>
<div class="footer">
<img border="0" src="horiz_grey_line.gif">
</div>
<div class="footer">
<img border="0" src="contacthelp.png">
</div>
<div class="footer">
<img border="0" src="nc_address.gif">
<img border="0" src="nc_webpolicy.gif">
</div>
</body>
I figured out the issue with this code. It should have been
uploadFile = {'uploadedfile': open('C:\\Users\\JOC-001\\Documents\\GIS\\IDOT\\ILWinterConditions.kmz', 'rb')}
to fit the form data. and 'payload' did not need the
'uploadedfile': 'C:\\Users\\JOC-001\\Documents\\GIS\\IDOT\\ILWinterConditions.kmz'

Find control of repeater nested in datalist on repeater item command

In my code repeater is nested in datalistdatalist contains checkboxes and radiobutton
i want to do database operation on checkchanged of checkboxes,so i had written this operation on repeater itemcomand. Here I am not able to find control of repeater.so please guide me how to find control of repeater.
My design is like this:
<asp:DataList ID="DatalistQues" runat="server" DataKeyField="QuestionID" OnSelectedIndexChanged="DataListText_SelectedIndexChanged"
Width="100%" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: 13%">
<asp:LinkButton ID="LinkButton6" runat="server" CommandName="Select" CssClass="ppppp">
<asp:Image ID="Image1" runat="server" ImageUrl='<% #Eval("Image")%>' Height="60px"
Width="65px" />
</asp:LinkButton>
</td>
<td style="width: 87%">
<asp:LinkButton ID="LinkButton7" runat="server" CommandName="Select" CssClass="ppppp">
<asp:Label ID="Label3" runat="server" Text='<% #Eval("name")%>'></asp:Label>
</asp:LinkButton>
</td>
</tr>
<tr>
<td style="width: 13%">
</td>
<td style="width: 87%; white-space: pre-line">
<asp:Label ID="TextBox2" runat="server" Text='<% #Eval("Question")%>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 13%">
</td>
<td style="width: 87%">
<script type="text/javascript" language="javascript">
function fnCheckUnCheck(objId) {
var grd = document.getElementById("TabContainer1_TabPanel2_DatalistQues");
alert(grd);
//Collect A
var rdoArray = grd.getElementsByTagName("input");
alert(rdoArray);
for (i = 0; i <= rdoArray.length - 1; i++) {
if (rdoArray[i].type == 'radio') {
if (rdoArray[i].id != objId) {
rdoArray[i].checked = false;
}
}
}
}
</script>
<asp:Repeater ID="RepeaterQues" runat="server" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table style="border: none">
<tr>
<td style="width: 100px">
<asp:LinkButton ID="LinkButton23" runat="server" CommandName="radiob">
<asp:RadioButton ID="RadioButton1" runat="server" onclick="fnCheckUnCheck(this.id);" /></asp:LinkButton><asp:LinkButton
ID="LinkButton24" runat="server" CommandName="checkb">
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Eval("QOption") %>' /></asp:LinkButton>
</td>
<td style="width: 100px">
<asp:Label ID="empname" Text='<%#Eval("QOption") %>' runat="server"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Try this
((Repeater)e.Item.Parent).ID // this gives the ID as specified on the aspx page
If you need Unique ID, you have to use this
((Repeater)e.Item.Parent).ClientID
On Item command of Repeater you will have to first find the naming container of sender
it will return you datalist item.
then in returned list item you will have to find the repeater of that particular data list itme
once you will find the repeater you can easily find the controls of the item of repeater