Scrape Javascript from an HTML page using C# .NET - c#

I have Website, which i need to scrap using C# HTML Agility Pack.
On the source code, i need the Array of URL's which is a Javascript Array. Please tell me how can i get this Array in Python
And the call from HTML to Javascript is like this:
<li class="accordion"><a class="xbrlviewer" onClick="javascript:highlight(this);" href="javascript:loadReport(1);">CONSOLIDATED BALANCE SHEETS</a></li>
<script type="text/javascript" language="javascript">
var reports = new Array(61);
reports[0] = "/Archives/edgar/data/320193/000119312512444068/R1.htm";
reports[1] = "/Archives/edgar/data/320193/000119312512444068/R2.htm";
reports[2] = "/Archives/edgar/data/320193/000119312512444068/R3.htm";
reports[3] = "/Archives/edgar/data/320193/000119312512444068/R4.htm";
reports[4] = "/Archives/edgar/data/320193/000119312512444068/R5.htm";
reports[5] = "/Archives/edgar/data/320193/000119312512444068/R6.htm";
reports[6] = "/Archives/edgar/data/320193/000119312512444068/R7.htm";
reports[7] = "/Archives/edgar/data/320193/000119312512444068/R8.htm";
reports[8] = "/Archives/edgar/data/320193/000119312512444068/R9.htm";
reports[9] = "/Archives/edgar/data/320193/000119312512444068/R10.htm";
reports[10] = "/Archives/edgar/data/320193/000119312512444068/R11.htm";
reports[11] = "/Archives/edgar/data/320193/000119312512444068/R12.htm";
reports[12] = "/Archives/edgar/data/320193/000119312512444068/R13.htm";
reports[13] = "/Archives/edgar/data/320193/000119312512444068/R14.htm";
reports[14] = "/Archives/edgar/data/320193/000119312512444068/R15.htm";
reports[15] = "/Archives/edgar/data/320193/000119312512444068/R16.htm";
reports[16] = "/Archives/edgar/data/320193/000119312512444068/R17.htm";
reports[17] = "/Archives/edgar/data/320193/000119312512444068/R18.htm";
reports[18] = "/Archives/edgar/data/320193/000119312512444068/R19.htm";
reports[19] = "/Archives/edgar/data/320193/000119312512444068/R20.htm";
reports[20] = "/Archives/edgar/data/320193/000119312512444068/R21.htm";
reports[21] = "/Archives/edgar/data/320193/000119312512444068/R22.htm";
reports[22] = "/Archives/edgar/data/320193/000119312512444068/R23.htm";
reports[23] = "/Archives/edgar/data/320193/000119312512444068/R24.htm";
reports[24] = "/Archives/edgar/data/320193/000119312512444068/R25.htm";
reports[25] = "/Archives/edgar/data/320193/000119312512444068/R26.htm";
reports[26] = "/Archives/edgar/data/320193/000119312512444068/R27.htm";
reports[27] = "/Archives/edgar/data/320193/000119312512444068/R28.htm";
reports[28] = "/Archives/edgar/data/320193/000119312512444068/R29.htm";
reports[29] = "/Archives/edgar/data/320193/000119312512444068/R30.htm";
reports[30] = "/Archives/edgar/data/320193/000119312512444068/R31.htm";
reports[31] = "/Archives/edgar/data/320193/000119312512444068/R32.htm";
reports[32] = "/Archives/edgar/data/320193/000119312512444068/R33.htm";
reports[33] = "/Archives/edgar/data/320193/000119312512444068/R34.htm";
reports[34] = "/Archives/edgar/data/320193/000119312512444068/R35.htm";
reports[35] = "/Archives/edgar/data/320193/000119312512444068/R36.htm";
reports[36] = "/Archives/edgar/data/320193/000119312512444068/R37.htm";
reports[37] = "/Archives/edgar/data/320193/000119312512444068/R38.htm";
reports[38] = "/Archives/edgar/data/320193/000119312512444068/R39.htm";
reports[39] = "/Archives/edgar/data/320193/000119312512444068/R40.htm";
reports[40] = "/Archives/edgar/data/320193/000119312512444068/R41.htm";
reports[41] = "/Archives/edgar/data/320193/000119312512444068/R42.htm";
reports[42] = "/Archives/edgar/data/320193/000119312512444068/R43.htm";
reports[43] = "/Archives/edgar/data/320193/000119312512444068/R44.htm";
reports[44] = "/Archives/edgar/data/320193/000119312512444068/R45.htm";
reports[45] = "/Archives/edgar/data/320193/000119312512444068/R46.htm";
reports[46] = "/Archives/edgar/data/320193/000119312512444068/R47.htm";
reports[47] = "/Archives/edgar/data/320193/000119312512444068/R48.htm";
reports[48] = "/Archives/edgar/data/320193/000119312512444068/R49.htm";
reports[49] = "/Archives/edgar/data/320193/000119312512444068/R50.htm";
reports[50] = "/Archives/edgar/data/320193/000119312512444068/R51.htm";
reports[51] = "/Archives/edgar/data/320193/000119312512444068/R52.htm";
reports[52] = "/Archives/edgar/data/320193/000119312512444068/R53.htm";
reports[53] = "/Archives/edgar/data/320193/000119312512444068/R54.htm";
reports[54] = "/Archives/edgar/data/320193/000119312512444068/R55.htm";
reports[55] = "/Archives/edgar/data/320193/000119312512444068/R56.htm";
reports[56] = "/Archives/edgar/data/320193/000119312512444068/R57.htm";
reports[57] = "/Archives/edgar/data/320193/000119312512444068/R58.htm";
reports[58] = "/Archives/edgar/data/320193/000119312512444068/R59.htm";
reports[59] = "/Archives/edgar/data/320193/000119312512444068/R60.htm";
reports[60] = 'all';

Related

Lightswitch Updating() method not saving any data in DB

I am trying to save the entity data using General methods of lightswitch, which is Updating. Below is the following code. I am not able to figure out what I am missing. There is no error in the code or in the UI. Its just that nothing gets saved.
partial void viewFamilyProcessDatas_Updating(viewFamilyProcessData entity)
{
var AutoAddMissingListing = entity.AutoAddMissingListing;
var AutoAddOddLots = entity.AutoAddOddLots;
var DefaultFilterValue = entity.DefaultFilterValue;
var ExcludeZeroNumberOfUnits = entity.ExcludeZeroNumberOfUnits;
//objFamilyProcessData.FamilyID = entity.FamilyID;
var IgnoreForPricing = entity.IgnoreForPricing;
var LimitEndDate = entity.LimitEndDate;
var OffsetFromMaxAsAtDate = entity.OffsetFromMaxAsAtDate;
var PrefilterConstituents = entity.PrefilterConstituents;
var TimeDataExpires = entity.TimeDataExpires;
entity.AutoAddMissingListing = AutoAddMissingListing;
entity.AutoAddOddLots = AutoAddOddLots;
entity.DefaultFilterValue = DefaultFilterValue;
entity.ExcludeZeroNumberOfUnits = ExcludeZeroNumberOfUnits;
entity.IgnoreForPricing = IgnoreForPricing;
entity.LimitEndDate = LimitEndDate;
entity.OffsetFromMaxAsAtDate = OffsetFromMaxAsAtDate;
entity.PrefilterConstituents = PrefilterConstituents;
entity.TimeDataExpires = TimeDataExpires;
//this.DataWorkspace.SolaDBServerData.Details.DiscardChanges();
entity.Details.DiscardChanges();
}
The solution to this finally came to this:
partial void vwFamilyProcessDatas_Updating(vwFamilyProcessData entity)
{
if(entity.Details.EntityState.ToString() == "Modified")
{
var AutoAddMissingListing = entity.AutoAddMissingListing;
var AutoAddOddLots = entity.AutoAddOddLots;
var DefaultFilterValue = entity.DefaultFilterValue;
var ExcludeZeroNumberOfUnits = entity.ExcludeZeroNumberOfUnits;
var IgnoreForPricing = entity.IgnoreForPricing;
var LimitEndDate = entity.LimitEndDate;
var OffsetFromMaxAsAtDate = entity.OffsetFromMaxAsAtDate;
var PrefilterConstituents = entity.PrefilterConstituents;
var TimeDataExpires = entity.TimeDataExpires;
tblFamily objFamily = tblFamilies.Where(f => f.FamilyID == entity.FamilyID).Single();
objFamily.AutoAddMissingListing = AutoAddMissingListing;
objFamily.AutoAddOddLots = AutoAddOddLots;
objFamily.DefaultFilterValue = DefaultFilterValue;
objFamily.ExcludeZeroNumberOfUnits = ExcludeZeroNumberOfUnits;
objFamily.IgnoreForPricing = IgnoreForPricing;
objFamily.LimitEndDate = LimitEndDate;
objFamily.OffsetFromMaxAsAtDate = OffsetFromMaxAsAtDate;
objFamily.PrefilterConstituents = PrefilterConstituents;
objFamily.TimeDataExpires = TimeSpan.Parse(TimeDataExpires);
entity.Details.DiscardChanges();
}}

Adding Javascript to ASPX page with C#

I have some Javascript code and I want to add it to my page in Default.aspx.cs.
I tried the following:
string sb = #" <script type='text/javascript'>
var chart;
var chartData = [{'year': 2005,'income': 23.5,'expenses': 18.1},
{'year': 2006,'income': 26.2,'expenses': 22.8},
{'year': 2007, 'income': 30.1, 'expenses': 23.9 },
{'year': 2008,'income': 29.5,'expenses': 25.1},
{'year': 2009,'income': 24.6,'expenses': 25}
];
AmCharts.ready(function () {
chart = new AmCharts.AmSerialChart();
chart.dataProvider = chartData;
chart.categoryField = 'year';
chart.startDuration = 1;
chart.plotAreaBorderColor = '#DADADA';
chart.plotAreaBorderAlpha = 1;chart.rotate = true;var categoryAxis = chart.categoryAxis;
categoryAxis.gridPosition = 'start';
categoryAxis.gridAlpha = 0.1;
categoryAxis.axisAlpha = 0;var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0;
valueAxis.gridAlpha = 0.1;
valueAxis.position = 'top';
chart.addValueAxis(valueAxis);
var graph1 = new AmCharts.AmGraph();
graph1.type = 'column';
graph1.title = 'Income';
graph1.valueField = 'income';
graph1.balloonText = 'Income:[[value]]';
graph1.lineAlpha = 0;
graph1.fillColors = '#ADD981';
graph1.fillAlphas = 1;
chart.addGraph(graph1);
var graph2 = new AmCharts.AmGraph();
graph2.type = 'column';
graph2.title = 'Expenses';
graph2.valueField = 'expenses';
graph2.balloonText = 'Expenses:[[value]]';
graph2.lineAlpha = 0;
graph2.fillColors = '#81acd9';
graph2.fillAlphas = 1;
chart.addGraph(graph2);var legend = new AmCharts.AmLegend();
chart.addLegend(legend); chart.creditsPosition = 'top-right';
chart.write('chartdiv');
});
</script>";
ScriptManager.RegisterStartupScript(this.Page,
this.GetType(), "MyFun1", sb, false);
The code works when directly added to the aspx page, but when I try this and try any other code I can't run it on my page.
I will fill values from database . So it must be dynamically
edit: I solved the problem. I added a label on page and wrote this code
Label5.Text = sb;
The problem is the code has comments. It makes some of the javascript code invalid when render to browser, so remove those comments and try again.
For debugging, you can try render the script to Literal control first, and see any script error in Console.
string sb = #" <script type='text/javascript'>
var chart;
var chartData = [{ 'year': 2005, 'income': 23.5,'expenses': 18.1},
AmCharts.ready(function () {
chart = new AmCharts.AmSerialChart();
chart.dataProvider = chartData;
chart.categoryField = 'year';
chart.startDuration = 1;
chart.plotAreaBorderColor = '#DADADA';
chart.plotAreaBorderAlpha = 1;
chart.rotate = true;
var categoryAxis = chart.categoryAxis;
categoryAxis.gridPosition = 'start';
categoryAxis.gridAlpha = 0.1;
categoryAxis.axisAlpha = 0;
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0;
valueAxis.gridAlpha = 0.1;
valueAxis.position = 'top';
chart.addValueAxis(valueAxis);
var graph1 = new AmCharts.AmGraph();
graph1.type = 'column';
graph1.title = 'Income';
graph1.valueField = 'income';
graph1.balloonText = 'Income:[[value]]';
graph1.lineAlpha = 0;
graph1.fillColors = '#ADD981';graph1.fillAlphas = 1;
chart.addGraph(graph1);
var graph2 = new AmCharts.AmGraph();
graph2.type = 'column';
graph2.title = 'Expenses';
graph2.valueField = 'expenses';
graph2.balloonText = 'Expenses:[[value]]';
graph2.lineAlpha = 0;
graph2.fillColors = '#81acd9';
graph2.fillAlphas = 1;
chart.addGraph(graph2);
var legend = new AmCharts.AmLegend();
chart.addLegend(legend);
chart.creditsPosition = 'top-right';
chart.write('chartdiv');
});
</script>";
ScriptManager.RegisterStartupScript(this.Page,
this.GetType(), "MyFun1", sb, false);

Viewing XML output from C#

I'm trying to work with the UPS api to create a shipping label. The UPS api uses a webservice to send an XML request to UPS. UPS then sends a response back. Here is my question.
Is there a way to view the XML that is outputted when I call the "shipmentRequest" method?
This is the first time I've used an API and a webservice so if you need me to provide more information just let me know.
Thanks!
EDIT: Here is my C# code
ShipService shpSvc = new ShipService();
ShipmentRequest shipmentRequest = new ShipmentRequest();
UPSSecurity upss = new UPSSecurity();
//shpSvc.Url = "https://onlinetools.ups.com/webservices/Ship";
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = apiCode;
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = userName;
upssUsrNameToken.Password = password;
upss.UsernameToken = upssUsrNameToken;
shpSvc.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "nonvalidate" };
request.RequestOption = requestOption;
shipmentRequest.Request = request;
ShipmentType shipment = new ShipmentType();
shipment.Description = "Ship webservice example";
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = accountNumber;
PaymentInfoType paymentInfo = new PaymentInfoType();
ShipmentChargeType shpmentCharge = new ShipmentChargeType();
BillShipperType billShipper = new BillShipperType();
billShipper.AccountNumber = accountNumber;
shpmentCharge.BillShipper = billShipper;
shpmentCharge.Type = "01";
ShipmentChargeType[] shpmentChargeArray = { shpmentCharge };
paymentInfo.ShipmentCharge = shpmentChargeArray;
shipment.PaymentInformation = paymentInfo;
ShipWSSample.ShipWebReference.ShipAddressType shipperAddress = new ShipWSSample.ShipWebReference.ShipAddressType();
String[] addressLine = { "480 Parkton Plaza" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "Timonium";
shipperAddress.PostalCode = "21093";
shipperAddress.StateProvinceCode = "MD";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipper.Name = "ABC Associates";
shipper.AttentionName = "ABC Associates";
ShipPhoneType shipperPhone = new ShipPhoneType();
shipperPhone.Number = "1234567890";
shipper.Phone = shipperPhone;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
ShipWSSample.ShipWebReference.ShipAddressType shipFromAddress = new ShipWSSample.ShipWebReference.ShipAddressType();
String[] shipFromAddressLine = { "Ship From Street" };
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "Timonium";
shipFromAddress.PostalCode = "21093";
shipFromAddress.StateProvinceCode = "MD";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipFrom.AttentionName = "Mr.ABC";
shipFrom.Name = "ABC Associates";
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "Some Street" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "Roswell";
shipToAddress.PostalCode = "30076";
shipToAddress.StateProvinceCode = "GA";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipTo.AttentionName = "DEF";
shipTo.Name = "DEF Associates";
ShipPhoneType shipToPhone = new ShipPhoneType();
shipToPhone.Number = "1234567890";
shipTo.Phone = shipToPhone;
shipment.ShipTo = shipTo;
ServiceType service = new ServiceType();
service.Code = "01";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "1";
ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType();
uom.Code = "LBS";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
PackagingType packType = new PackagingType();
packType.Code = "02";
package.Packaging = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
LabelSpecificationType labelSpec = new LabelSpecificationType();
LabelStockSizeType labelStockSize = new LabelStockSizeType();
labelStockSize.Height = "6";
labelStockSize.Width = "4";
labelSpec.LabelStockSize = labelStockSize;
LabelImageFormatType labelImageFormat = new LabelImageFormatType();
labelImageFormat.Code = "SPL";
labelSpec.LabelImageFormat = labelImageFormat;
shipmentRequest.LabelSpecification = labelSpec;
shipmentRequest.Shipment = shipment;
ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest);
MessageBox.Show("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description);
MessageBox.Show("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber);
You can inherit from the UPS service and read the response as xml by providing your own XmlWriter by overriding GetWriterForMessage(). You can see a working example here.
i am using this code display xml it may help you.
XDocument mySourceDoc = new XDocument();
mySourceDoc = XDocument.Load(shipmentResponse);
txtxml.Text = mySourceDoc.ToString();

How do i parse my array to my model

I have made a ajax post and stringifyed my json and send the data to my controller method:
The data that the controller recieves looks like this:
"[\"0041300201\",1610612764,\"WAS\",\"Washington\",2772,\"Trevor Ariza\",\"F\",\"\",\"37:20\",7,10,0.7,6,6,1,2,4,0.5,1,5,6,2,1,0,0,3,22,18]"
My controller method:
public void addBoxScore(string playerstats)
{
Games gamestats = new Games();
gamestats.GAME_ID = playerstats[0];
gamestats.TEAM_ID = playerstats[1];
gamestats.TEAM_ABBREVIATION = playerstats[2].ToString();
gamestats.TEAM_CITY = playerstats[3].ToString();
gamestats.PLAYER_ID = playerstats[4];
gamestats.PLAYER_NAME = playerstats[5].ToString();
gamestats.START_POSITION = playerstats[6].ToString();
gamestats.COMMENT = playerstats[7].ToString();
gamestats.MIN = playerstats[8];
gamestats.FGM = playerstats[9];
gamestats.FGA = playerstats[10];
gamestats.FG_PCT = playerstats[11];
gamestats.FGTHREEM = playerstats[12];
gamestats.FGTHREEA = playerstats[13];
gamestats.FGTHREE_PCT = playerstats[14];
gamestats.FTM = playerstats[15];
gamestats.FTA = playerstats[16];
gamestats.FT_PCT = playerstats[17];
gamestats.OREB = playerstats[18];
gamestats.DREB = playerstats[19];
gamestats.REB = playerstats[20];
gamestats.AST = playerstats[21];
gamestats.STL = playerstats[22];
gamestats.BLK = playerstats[23];
gamestats.TO = playerstats[24];
gamestats.PF = playerstats[25];
gamestats.PTS = playerstats[26];
gamestats.PLUS_MINUS = playerstats[27];
}
When i do this the gamestats.Game_ID becomes "91" instead of "0041300201" as i wanted it to be.
Please use this array or list of string instead of only strings. like this
public void addBoxScore(string[] playerstats)

Expedia hotel API

I am working on Expedia hotel API.All the function are working except booking.All the other request using GET method for requesting.But in booking we have to use the POST method with different URL.So i changed the URL for request but still getting the error.
My codes are
HotelServicesImplService client = new HotelServicesImplService();
HotelRoomReservationRequest bookreq = new HotelRoomReservationRequest();
HotelRoomReservationResponse bookres = new HotelRoomReservationResponse();
addressInfo bookad = new addressInfo();
reservationInfo bookinfo = new reservationInfo();
client.Url = "https://book.api.ean.com/ean-services/rs/hotel/v3";
//bookreq.minorRevSpecified = true;
//bookreq.minorRev = 25;
bookreq.hotelId = 106347;
bookreq.apiKey = "api";
bookreq.cid = "cid";
bookreq.arrivalDate = "12/11/2013";
bookreq.departureDate = "12/13/2013";
bookreq.supplierType = SupplierType.E;
bookreq.rateKey = "af00b688-acf4-409e-8bdc-fcfc3d1cb80c";
bookreq.roomTypeCode = "198058";
bookreq.rateCode = "484072";
bookreq.RoomGroup = new[] { new Room
{
numberOfAdults=Convert.ToInt32(2),
numberOfChildren=Convert.ToInt32(0),
childAges=new int[] {} ,
firstName="Test Booking",
lastName="Test Booking",
bedTypeId="23",
smokingPreference=SmokingPreference.NS,
}};
float i = float.Parse("231.18");
bookreq.currencyCode = "USD";
bookreq.chargeableRate = i;
bookinfo.email = "ranaabhi007#yahoo.com";
bookinfo.firstName = "TestBooking";
bookinfo.lastName = "TestBooking";
bookinfo.homePhone = "2145370159";
bookinfo.workPhone = "2145370159";
bookinfo.creditCardType = "CA";
bookinfo.creditCardNumber = "5401999999999999";
bookinfo.creditCardIdentifier = "TestBooking";
bookinfo.creditCardExpirationMonth = "12";
bookinfo.creditCardExpirationYear = "2015";
bookad.city = "Seattle";
bookad.stateProvinceCode = "WA";
bookad.countryCode = "US";
bookad.postalCode = "98004";
bookreq.ReservationInfo = bookinfo;
bookad.address1 = "travelnow";
//bookad.city = txtCity.Text;
//bookad.stateProvinceCode = txtState.Text;
//bookad.countryCode = txtCountry.Text;
//bookad.postalCode = txtPostal.Text;
bookreq.AddressInfo = bookad;
bookres = client.getReservation(bookreq);
// HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(client);
Response.Write(bookres.confirmationNumbers);
Response.Write(bookres.departureDate);
Response.Write(bookres.drivingDirections);
Response.Write(bookres.CouponInformationResponse);
but i am still getting the error
The request failed with HTTP status 404: Not Found.
Are you sure your URL is correct? According to the documentation, it should be
https://book.api.ean.com/ean-services/rs/hotel/v3/res

Categories