Extracting Script Information for Web Scraping Code - python-3.x

I managed to isolate this tag shown below and I'm trying to extract the product title, sale price, and stock information as variables.
Its type is class 'bs4.element.Tag'
<script type="text/javascript">
var utag_data = {page_breadcrumb:'Home > Components > Computer Cases > Computer Cases > Fractal Design > Item#:N82E16811352069',
page_tab_name:'Components',
product_category_id:['9'],
product_category_name:['Computer Cases'],
product_subcategory_id:['7'],
product_subcategory_name:['Computer Cases'],
product_id:['11-352-069'],
product_web_id:['N82E16811352069'],
product_title:['Fractal Design Focus G Black ATX Mid Tower Computer Case'],
product_manufacture:['Fractal Design'],
product_sale_price:['99.99'],
product_default_shipping_cost:['12.99'],
product_model:['FD-CA-FOCUS-BK-W'],
product_instock:['1'],
product_group_id:['6055851'],
page_type:'Product',
site_region:'CAN',
site_currency:'CAD',
page_name:'NewProductDetail',
search_scope:jQuery('#haQuickSearchStore option:selected').text(),
user_nvtc:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.NVTC),
user_name:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.LOGIN,'LOGINID6'),
third_party_render:[]
};
var description = Biz.Common.QuickSearch.getUrlSearch('Description');
var d = Biz.Common.QuickSearch.getUrlSearch('d');
if(description)
{
utag_data.search_keyword = description;
}
else if(d)
{
utag_data.search_keyword = d;
}
</script>
I'm having trouble accessing the utag_data. I haven't been able to index the product info using numbers or by calling the header. The contents of the entire script seem to be stored in one entry.

managed to isolate this tag
I'd recommend to apply regex to the isolated tag content.
/utag_data = {([^}]+)};/
The first group will contain the target data:
page_breadcrumb:'Home > Components > Computer Cases > Computer Cases > Fractal Design > Item#:N82E16811352069',\n page_tab_name:'Components',\n product_category_id:['9'],\n product_category_name:['Computer Cases'],\n product_subcategory_id:['7'],\n product_subcategory_name:['Computer Cases'],\n product_id:['11-352-069'],\n product_web_id:['N82E16811352069'],\n product_title:['Fractal Design Focus G Black ATX Mid Tower Computer Case'],\n product_manufacture:['Fractal Design'],\n product_sale_price:['99.99'],\n product_default_shipping_cost:['12.99'],\n product_model:['FD-CA-FOCUS-BK-W'],\n product_instock:['1'],\n product_group_id:['6055851'],\n page_type:'Product',\n site_region:'CAN',\n site_currency:'CAD',\n page_name:'NewProductDetail',\n search_scope:jQuery('#haQuickSearchStore option:selected').text(),\n user_nvtc:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.NVTC),\n user_name:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.LOGIN,'LOGINID6'),\n third_party_render:[]\n\n
Then split it by semicolon ; and extract from key-values by splitting by :.

Related

How to set compound structure for two different layers if I used 2 different categories of material for wall structure , using revit api

I am trying to create a wall with 2 layers and each layer materials are different. When I try to set the CompoundStructure for the wall I am getting an exception that CompoundStructure is not valid.
CompoundStructure cStructure = CompoundStructure.CreateSimpleCompoundStructure(clayer);
wallType.SetCompoundStructure(cStructure);
Can anyone tell me how I can create compound structure for layers with different materials?
First of all, solve your task manually through the end user interface and verify that it works at all.
Then, use RevitLookup and other database exploration tools to examine the results in the BIM elements, their properties and relationships.
Once you have done that, you will have a good idea how to address the task programmatically – and have confidence that it will work as expected:
How to research to find a Revit API solution
Intimate Revit database exploration with the Python Shell
newWallMaterial = wallMaterial.Duplicate("newCreatedMaterial");
newWallmaterial2 = wallMaterial.Duplicate("NewCreatedMAterial2");
//roofMaterial3 = roofMaterial2.Duplicate("NewCreatedMAterial3");
bool usr = newWallMaterial.UseRenderAppearanceForShading;
//newWallMaterial.Color = BuiltInTypeParam.materialCol;
foreach (Layers layer in layers)
{
if (layer.layerId == 0)
{
c = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallMaterial.Id);
newWallMaterial.Color = color;
clayer.Add(c);
}
if (layer.layerId == 1)
{
c1 = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallmaterial2.Id);
newWallmaterial2.Color = color;
clayer.Add(c1);
}

Highlight Duplicate list item in SharePoint 2013

I have a SharePoint 2013 (The Cloud version) custom list where 1 column is a text field where contact numbers are keyed in.
How can I get SharePoint to highlight duplicate values in that column so that every time a new item is added to the list, I'll know if the contact number has been used previously?
Ideally, here's what I'd get if I were to enter 816's details for the 2nd time:
CNO....Name.......Issue
816.....Blink........Login Problem (highlighted in red)
907.....Sink.........Access Denied
204.....Mink.........Flickering Screen
816.....Blink........Blank Screen (highlighted in red)
I've been struggling with this for awhile and would be very grateful for any advice. Thanks!
Since SharePoint 2013 uses Client Side Rendering (CSR) as a default rendering mode I would recommend the following approach. Basically the idea is to customize List View on the client side as demonstrated below.
Assume the Requests list that contains RequestNo column.
The following JavaScript template is intended for highlighting the rows when list item with RequestNo column occurs more then once:
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
var rows = ctx.ListData.Row;
var counts = getItemCount(rows,'RequestNo'); //get items count
for (var i=0;i<rows.length;i++)
{
var count = counts[rows[i]["RequestNo"]];
if (count > 1)
{
var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
var tr = document.getElementById(rowElementId);
tr.style.backgroundColor = "#ada";
}
}
}
});
function getItemCount(items,propertyName)
{
var result = {};
for(var i = 0; i< items.length; i++) {
var groupKey = items[i][propertyName];
result[groupKey] = result[groupKey] ? result[groupKey] + 1 : 1;
}
return result;
}
How to apply the changes
Option 1:
Below is demonstrated probably one of easiest way how to apply those changes:
Open the page in Edit mode
Add Content Editor or Script Editor web part on the page
Insert the specified JavaScript template by enclosing it using
script tag into web part
Option 2:
Save the specified JavaScript template as a file (let's name it duplicatehighlight.js) and upload it into Site Assets library
Open the page in Edit mode and find JSLink property in List View web part
Specify the value: ~sitecollection/SiteAssets/duplicatehighlight.js and save the changes.
Result
SharePoint has some basic conditional formatting for Data View Web Parts and XSLT List Views, but the conditions you can use are rather limited. You can compare a field in the current item with a value that you specify. There are no formulas to count the number of items with the same name or similar, which would be the approach to use to identify duplicates.
If you need to identify duplicates, you may want to create a view that groups by the CNO number. Grouping will also include an item count, so you can run down the list and spot groups with more than one item.

How to limit child category depth in expression engine's Control Panel?

Does anyone know if it is possible and how to limit the depth of child categories from the backend (Control Panel) in ExpressionEngine?
The idea is to allow someone to add their own category hierarchy from the Control Panel, but limiting them to 4 child categories, for instance:
All > 5 Star > Entertainment > Movies > Animated
but not this:
All > 5 Star > Entertainment > Movies > Animated > 3D
This is just an example.
Any help would be greatly appreciated.
No, not unless you write your own Extension to tap into EE general display hooks (the category add/edit/listing doesn't have any hooks).
Easiest approach would be to use CP CSS JS add-on and code your own JS to prevent the selection too deep.
Target something like $(".category_field select#parent_id") and if the category parent selection has 32 spaces (4x8) Array(33).join(" ") then don't allow the selection and move up the options until you find an option (category parent) that has less spaces (i.e. isn't as deep).
This might work (untested)...
$(".category_field select#parent_id").change( function() {
var $selected = $(this).children("option:selected")
if ($selected.text().indexOf( Array(33).join(" ") ) >= 0) {
// Too deep
$selected.prevAll().each(function(){
if ($(this).text().indexOf( Array(33).join(" ") ) < 0 ) {
$(this).parent().children('option:selected').removeProp('selected');
$(this).prop('selected', true);
return;
}
});
}
});

SharePoint 2010 Two search boxes on the master page

I would like to have two search boxes on my master page.
One that would search for content and the other one that would search for people.
I see the code in the master page that searches for content:
How would i do to add another box that searches for people?
if you know or have info on how to achieve this I would appreciate it.
thank you much
W
You can do something simple which is to put an HTML text box directly in your master page. It may not be as elegant as writing a customer user control that reads the location of the Search site, but if the URL to your search results page is static then something like this might work for you:
<script type="text/javascript">
function SearchPeople()
{
var termArr = document.getElementById("SearchTextBoxPeople").value.split(" ");
var retStr = "";
for (var i = 0; i < termArr.length; i++) {
retStr += termArr[i] + "* ";
}
document.location.href = "/Search/Pages/peopleresults.aspx?k=" + retStr;
}
</script>
<input type="text" id="SearchTextBoxPeople" />
Search People
One additional benefit of this is that you can control the input to include wildcards (which are horrible out-of-the-box for people searches). The JavaScript is simply including * in the search which allows wildcard searches. So a search for jo sm will actually send jo* sm* to the search page which will then match on John Smith.

How can I change the width of a column in a list view is SharePoint?

I have SharePoint 2007 and I have a list view that has a text field that, when shown with quite a few other fields, is only about 1 word narrow.
Is there a way to expand that column without access to css or other web programming languages?
If you can't use CSS, JavaScript, SharePoint Designer, or deploy any C# code to the server.. then you can't change the width of the column.
Try adding a ContentEditor Web Part with the CSS/JavaScript that sets the look of the column. You don't need C# or Designer.
I did something similar with a search page where I needed a JavaScript function to be triggered so I added a CEWP to the page with the following code (see below).
You could change this to look for the id of the column you want to modify. Just remember that ID's of controls in SharePoint are generated during the page render so you won't necessarily know the exact ID. That is why this code looks for an anchor with an ID that ends with '_PSB_Show', instead of looking for the exact ID.
<script type="text/javascript">
var anchors = document.getElementsByTagName("a");
var anchor;
var j;
// Iterate through all anchors on the page and find the one with ID ending in _PSB_Show
for (j = 0; j < anchors.length; j++)
{
if (anchors[j].id.match(/\_PSB_Show$/) != null)
{
anchor = anchors[j];
break;
}
}
// If the anchor is found and the click is supported in the current browser
// Perform a click after 100 ms
if ((anchor != null) && (anchor.click != null))
{
setTimeout("anchor.click();", 100);
}
</script>

Resources