Select all text before <br> - html

I have the following awful HTML:
<p>
102036 - <em>In re</em> State v. Williams video<br>
104236 - University of Kansas Hosp. Auth. v. Board of Wabaunsee County Comm'rs video
</p>
I want to use XPath to capture all of the text following each </a>, so:
Item 1: " - In re State v. Williams
Item 2: " - University of Kansas Hosp. Auth. v. Board of Wabunsee County
Alternatively, I could just capture all text, and that would be fine too:
Item 1: "102036 - In re State v. Williams
Item 2: "104236 - University of Kansas Hosp. Auth. v. Board of Wabunsee County
I've been trying various things for a while now, but making no progress. I want something like:
/a/following::text()[before::br]
Help?

Here you go, pal:
//a//following-sibling::text() | //a//following-sibling::*[not(self::a)]/text()

The best thing I've found so far is to simply nuke the errant <em> nodes.
So:
elem = html.xpath('//p')[0]
etree.strip_tags(elem, 'em')
Then, using the cleaner html, a simple XPath can be used:
texts = [e.tail for e in elem.xpath('//a')]
Credit where due: https://stackoverflow.com/a/8788559/64911

If you have firebug installed and are running Firefox, for this and all future xpath needs you can just follow this tutorial:
http://www.wikihow.com/Find-XPath-Using-Firebug
Very easy way to find the xpath for anything on a page.

Related

Text align justify on li moves bullets on text in Firefox

Text align justify moves bullet points on the text contents on certain line in Firefox. Is there a way to avoid this behavior.
Below snippet will show the anomaly if you open it in Firefox. It works fine in Chrome & IE (I checked in IE10/IE11).
As showing on Firefox:
As showing in Chrome
ul li{text-align:justify;}
<ul>
<li>Property was occupied by Doe Family for past 17 years where in seller Mr. John Doe owner of collateral through CD claims execution of sale deed with mutual consent. On joint visit by credit and sales team it was found that there are two parallel title chain of the collateral:</li>
<li>Way back in 2000-01 John Doe and his brother entered into collaboration with some Creater Jane Doe and it was decided that G+2 structure will be built. GF & 1st will go to both the brothers and 2nd to builder. But no collaboration agreement was entered on paper. Further builder breaching the mutually agreed terms constructed 3rd floor as well -> Accordingly builder claimed occupancy n rights on both 2nd and 3rd floor – property went into dispute</li>
</ul>
You can try to use the below property:
list-style-position: outside;
Please check the following link

Chrome Devtools, copying over a set of answers

I have to do this repeatedly, so I was wondering if there was a working around....
here is a set of amenities for an apartment, they have to be transferred to a larger list containing those amenities by clicking off multiple choice cirlces. Is there away to edit the script to do it all at once>
example
accessible
air conditioning
dishwasher
garage
hardwood floors
parking
patio / balcony
gym
in unit laundry
cats allowed
dogs allowed
pet friendly
basketball court
bathtub
bbq/grill
bike storage
business center
carpet
ceiling fan
clubhouse
game room
granite counters
microwave
oven
package receiving
playground
pool table
range
refrigerator
stainless steel
walk in closets
I think you want to just checkmark all of the checkboxes on the amenities list so something like this will work:
$('div.whitelist-searchable-amenity input[type=checkbox]').each(function(){
$(this).prop('checked', true);
});
https://jsfiddle.net/r62qgou3/
Edit:
I am not sure of what you mean by "copying text to script" but I modified the script to check if the values that you are looking for are within the document. This should search the values of the checkboxes and then you can use your own script to "copy" the value elsewhere. Just add more values to the array if you need more keywords.
x = [
"accessible",
"air conditioning",
"dishwasher",
"garage",
];
$('div.whitelist-searchable-amenity input[type=checkbox]').each(function(){
if(x.indexOf(this.value) > -1)
{
alert("copy here");
}
});

What's stopping these variable's from being defined in my code?

I've been designing this game, and Ive come across a weird problem. Now maybe it's just something simple I've missed or some way I formatted it. When I run my code I get these errors that suggest that none of the variables I've been defining are being declared/defined. On top of that none of the functions seem to run... Should I define text1, button1Name, etc... as Global variable? or is their a better way?
##Project 1 v4
##Structure whole program with base functionality
##Begin with an outline then fill in functions and windows from V2, and V3.
import Tkinter
import random
inventory=[]
playCount=0
def startGame():
##adds name
##button that calls StoryCard
text1="Welcome to Treasure Quest!! The Game that allows you to pick your own destiny! Treasure quest is a very simple game. The story will display on the screen until it reaches an event. At each event you will be shown two choices. Each decision may cause you to leave with more treasure or to die a horrible death... Still like any true or false question on a final exam, you only have a 50/50 chance of ruining your entire life if you do not know! Now that you know how to play, please click the button below to start the game!"
button1= introCard()
button1Name="Play"
button2= win.destroy
button2Name="Quit"
def introCard():
text1="You are the bravest knight in the service of the great kingdom Universitas! The kingdom has long been an icon throughout the world, but now it faces great peril. The king of Universitas has foolishly spent the entirety of the kingdoms fortune shopping online. The only hope for the kingdom, is to find the money to pay off it's debts. Luckily recently some scrolls have been found that describe the locations of hidden treasures. You have been selected to find these treasures. Do you except?"
button1=winCard()
outcome1="You embark upon your quest!"
button1Name="Accept!"
button2=lossCard()
outcome2="The kingdom falls into debt and you die of dysentary... Nice going Oregon Trail..."
button2Name="Decline!"
def storyCard(n):##This function will randomly select a story chunk
##recieves a random int
##tests for true int w/ if then else line
##Story blurbs for these are stored in V2 copy them!
if n ==1:
text1="You come across a dark cave... A dragon is said to lurk within... You enter and see the Holy Sword... How do you take it?"
button1=lossCard()
outcome1="The dragon bakes you to a crisp... Sorry!"
button1Name="Bargain for it!"
button2=winCard()
outcome2="Victory! You sneak past the dragon and make off with the sword!"
button2Name="Steal it!"
#get="Holy Sword"
elif n==2:
text1="You come across a mummys tomb... You see two doors. Take the front entrance or the hidden entrance?"
button1=winCard()
outcome1="The mummy is awake and glad for company! He feeds you tea and sets you on your way with gifts!"
button1Name="Front"
#get="A beautiful glass vase!"
button2=lossCard()
outcome2="The mummy sees you! It screams thief! and shivs you..."
button2Name="Hidden"
elif n==3:
text1="You come across a magic tree inhabited by elves. They ask you to climb up and see their beautiful home."
button1=lossCard()
outcome1="You climb high but slip off a branch and fall to your death. The elves laugh."
button1Name="Climb"
button2=winCard()
outcome2="The elves are perplexed as to why you do not want to see them. They come down and give you a new couch to show off their things."
button2Name="Stay"
#get="A rad couch"
elif n==4:
text1="You come across a cave filled with strange lights! A troll stands guard."
button1=winCard()
outcome1="This is a hip and happening new dwarven nightclub! The troll lets you in because you seem cool! The dwarves give you some rare cave mushrooms. It seems lame but they said the kings a regular and they will go over well. You have a fun night... You drink to much ale and get a late start the next morning though..."
button1Name="Strut in!"
#get="Rare Mushrooms"
button2=winCard()
outcome2="This is actually a hip new dwarven nightclub! The bouncer troll won't let you in though... Oh well! dwarves are hipsters anyways! Gratefull for your company the troll gives you an amulet!"
button2Name="Wait in line."
#get="Sweet Amulet"
elif n==5:
text1="You come across a hut in the woods! Its owned by Merlin! The great wizard starts up conversation and invites you inside!"
button1=lossCard()
outcome1="Insulted, Merlin kills you with an axe... you would have expected magic... but no, Merlin is a psychopath and prefers to murder with axes."
button1Name="Leave"
button2=winCard()
outcome2="He talks about his GOD DAMNED GRANDKIDS FOR FOUR HOURS... He is grateful for you company however and lets you leave with his staff."
button2Name="Enter"
#get="A sweet Staff"
## each if, elif, ect must contain
##Text blurb
##Button 1 function def
##Button 2 function def
##button 1 name
##button 2 name
##Outcome 1 Text
##Outcome 2 Text
def winGame():
text1="CONGRATULATIONS!! You have collected enough treasure to pay off the kingdoms debts! You will forever be known to the people as a great knight! The king is in your debt!"
button1Name="Hooray!"
button1=win.destroy
button2Name="Huzzah!"
button2=win.destroy
def winCard():##Describes how event played out
#inventory.append[get]
playCount+=1
text1= outcome1 or outcome2
if playCount == 5:
button1Name="Onward!"
button1=winGame()
button2Name="Go Forth!"
button2=winGame()
else:
button1Name="Onward!"
button1=storyCard(random.randint(1,5))
button2Name="Go Forth!"
button2=storyCard(random.randint(1,5))
def lossCard():
text1=outcome1 or outcome2
button1Name="Game Over"
button1= win.destroy
button2Name="Game Over"
button2= win.destroy
startGame()
win=Tkinter.Tk()
win.title("TREASURE QUEST!!")
Textlabel=Tkinter.Label(win,text = text1,font=('Times New Roman',12),justify=LEFT,)
Textlabel.pack()
Row2=Tkinter.Frame(win)
Btn1=Tkinter.Button\
(Row2, text=button1Name, command=button1,font=('Times New Roman',12))
Btn2=Tkinter.Button\
(Row2, text=button2Name, command=button2, font=('Times New Roman',12))
Btn1.pack(side='left')
Btn2.pack(side='left')
Row2.pack()
win.mainloop()
When I run the code I get these errors:
Traceback (most recent call last):
File "C:/Users/Logan/Desktop/Project#1V4.py", line 141, in <module>
startGame()
File "C:/Users/Logan/Desktop/Project#1V4.py", line 17, in startGame
button1= introCard()
File "C:/Users/Logan/Desktop/Project#1V4.py", line 26, in introCard
button1=winCard()
File "C:/Users/Logan/Desktop/Project#1V4.py", line 116, in winCard
playCount+=1
UnboundLocalError: local variable 'playCount' referenced before assignment
If you want to change a global variable in a function, you need to use the keyword global as follows -
def winCard():##Describes how event played out
global playCount
#inventory.append[get]
playCount+=1

how to display data in html

In my project, I am retrieving an address from the database and displaying this address on page. The issue or problem that I am facing is the the way the retrieved address is being displayed.
Basically this is the way the address is being displayed:
Address: 1 Kings Street Kilmarnock East Berkshire Scotland KA1 UIT
I would like the address to be displayed like so:
Address: 1 Kings Street
Kilmarnock
East Berkshire
Scotland
KA1 UIT
How can I do this in HTML or css? I am currently using twitter bootstrap , and I don't if there is anyway to do using it.
Oh.. It's hard but let me try... ;)
<div>Address: 1 Kings Street<br> Kilmarnock <br>East Berkshire<br> Scotland <br>KA1 UIT</div>
Your Expected Output:
Address: 1 Kings Street
Kilmarnock
East Berkshire
Scotland
KA1 UIT
Working Demo
Note: This is just simplest and basic way.. But if Data is coming from any database dynamically then at-least you should explain in details from where it comes and by which object it can be accessible.. Then you can apply JS or regex functions... I hope you understand what I mean..
If you edited the data in your database, and used a comma between each line, you might be able to split the data. (your question doesn't state what language you are writing in (mvc/how data is being received).
However, once you have the string, you can use the String.split method (available in most languages), and hence could adapt your view accordingly.
So,
Address: 1 Kings Street, Kilmarnock, East Berkshire, Scotland, KA1 UIT
would become
{1 Kings Street}{ Kilmarnock}{ East Berkshire}{ Scotland}{ KA1 UIT}
which you could then do a foreach block, displaying them onto the screen as you requested
A possible alternative (although probably not easy), would be to extract the postcode, and call a google maps API call to receive the address - but again, this would be quite difficult.
At present, I cannot see how you would be able to expect a program to decide where to split the address into separate lines (unless you place them into different fields which was described in the comments).
You can add <p> to each line, or put <br> at the end of each lines.
But
If your retrieving the data from a database through a php variable you cannot do that with pure html / css, you'll need string manipulation with PHP.

UITextView: Replace Special Characters [duplicate]

in xml data is
<content_special>
SAT 17TH TEST test club cheap drinks £3 shots £5 bottles $beers
</content_special>
i get this string using this code
TBXMLElement *Content_Special=[TBXML childElementNamed:#"content_special" parentElement:Club];
NSString *Content_SpecialStr = [TBXML textForElement:Content_Special];
when i NSLog(#"Content_special:%#",Content_SpecialStr);
that print like this
Content_special:SAT 17TH TEST
test club
cheap drinks
£3 shots
£5 bottles
$beers
how can i get original sting which Display in Xlm ? Any suggestion...
Found Solution Using Google Toolbox for Mac GTMNSString+HTML.h ,GTMNSString+HTML.m And GTMDefines.h,
First #import "GTMNSString+HTML.h"
use like This: Content_SpecialStr = [Content_SpecialStr gtm_stringByUnescapingFromHTML];
Ensure your data xml file has utf-8 encoding http://www.w3schools.com/xml/xml_encoding.asp