I have the following url: https://www.amazon.com/#twotabsearchtextbox. When I click on this link I would like it to go to Amazon, select the search bar, and input a value. My question is: how do I modify the URL to insert a value into the search bar?
Example Input
URL: https://www.amazon.com/#twotabsearchtextbox
Value: Avengers Movie
Expected Output:
I know you can select elements. I've also seen this done before somewhere. However, I cannot find a resource that explains the identifiers used. I saw you could highlight it here but not insert.
Perhaps there's something I'm missing, but I'd populate the search link.
<a href="https://www.amazon.com/s?k=YOUR+SEARCH+VALUE">
Like previously mentioned, you can even populate the value to whatever you'd like using some javascript. For example:
You have an anchor with an id containing what you want to search.
<a id="star+wars">My Link</a>
We can use javascript to populate the search URL with your search term, then add it to the anchor using setAttribute
let yourLink = document.getElementById("star+wars");
let searchID = yourLink.id;
yourLink.setAttribute("href", "https://www.amazon.com/s?k=" + searchID);
JSFiddle: https://jsfiddle.net/L5afroh1/
Related
At work, one of the systems I use outputs voyage schedules. The URL for each voyage is constructed as the form address followed by ?voyageCode= followed by the voyage number, which is a two-letter route prefix and a three-digit voyage number.
Rather than use the standard form, which has a whole bunch of fields I never need to use, I want to build a simple page where I can just select the route and enter a voyage number.
In practical terms, I'm trying to build a form with the following:
A drop-down menu or set of radio buttons to select the two-letter route code;
A text field to enter the three-digit route code;
A button or link to combine those inputs into a link in the format [LINK]?voyageCode=[ROUTE CODE][VOYAGE NUMBER]
My HTML knowledge is pretty outdated, and I've never worked much with forms. Can anyone advise on how I can construct this?
Why don't you use a select tag for the dropdown and a classic input text for the route coude ?
Then for the link part, you should capture the click event on your button through onClick and then call a small function that'll basically do that :
function concatRouteCode(){
var select= document.getElementById("routeCodeLetters");
var routeCodeLetters = select.options[select.selectedIndex].value;
var routeCodeNumber = document.getElementById('routeCode').value;
return routeCodeLettres+routeCodeNumber;
}
If you really want to combine the codes into a single query parameter, you'll have to use Javascript to fetch the values of the two fields and change the location. You don't need Javascript if you put the values into separate parameters, as in ?routeCode=xx&voyageNumber=123. In that case you would just give the select element the attribute name=routeCode and the input field the attribute name=voyageNumber.
In case you want to go with the first approach, you'd have something like
document.getElementById("idOfSubmitButton").addEventListener("load", function() {
const routeCode = document.getElementById("idOfSelectElement").value;
const voyageNumber = document.getElementById("idOfInputField").value;
location.href = "base URL here" + "?voyageCode=" + routeCode + voyageNumber;
});
Within the Moodle (v. 3.5.7) Atto editor (using both Chrome and Firefox) I've been trying to assign an ID to a particular row class, "span9". My ultimate objective is to assign this a unique ID and reference this element via jquery so as to append another element within it.
The ISSUE is that once I add an ID (id="checklist01") and click save, the ID simply does not appear in the DOM, and seems to not exist. When I re-enter the atto editor however, voila, there it is just sitting there. So it's NOT being removed completely... just not expressed somehow?
I have 2 screenshots linked below showing (1) the editor view, with the element and assigned ID highlighted, and (2) a screenshot of the DOM once the changes have been saved, with that same area highlighted, without the assigned ID.
Screenshots of ID Missing from DOM
Bootstrap ver. 4
So far I've tried switching the placement of the id in the atto editor (class coming first vs second after ); tried to add a "span" in front of the id (for some reason, I was desperate); and really just searched all over for someone who has encountered something similar.
I'm not sure how much help the html will provide, but here it is:
<div class="row-fluid colored">
<div class="iconbox span3">
h4>Your Completion Status (%)</h4>
</div>
<div id="checklist01" class="span9">
</div>
</div>
I found the reason for the removal of id attributes.
id attributes are removed because "Checklist" activity used safe HTML function of Moodle. If you want to access id attributes of description HTML follow below steps.
Go to mod\checklist\locallib.php file.
Then search formatted_intro() function (which is around line number 880).
In that function they used Moodle's format_text() function to return description text.
In that function, they have used 3 parameters.
string $text The text to be formatted.
int $format Identifier of the text format to be used
object/array $options text formatting options
Replace
$opts = array('trusted' => $CFG->enabletrusttext);
to
$opts = array('trusted' => $CFG->enabletrusttext,'allowid'=>true);
Then save your file and check. By following the above steps you can use id attributes.
I search the documentation but I didn't know exactly how to call that.
I have a template Index2Name that return a name based on an index.
I'm trying to use that name in a link:
[[Articles/{{Index2Name|0001}}|{{Index2Name|0001}}]]
or
Image:Big-0001.png|link=Articles/{{Index2Name|0001}}|''{{Index2Name|0001}}''
In the last example, the name is printed but the link doesn't work. (In gallery element)
It doesn't work. The value from the template is printed but it is not converted to a link.
How can I make this works? And does this have a name? (For future reference)
EDIT: Index2Name is a simple switch returning a few words depending of the id. Since I'm using subpages I only want the name to appear (Example: MyArticle) but the link is Articles/MyArticle
Could you clarify exactly what you want to happen please. (Where you want to link and how you want it to look).
But for example if you use:
[[Image:Big-0001.png|''{{Index2Name|0001}}'']]
It will link to the page Image:Big-0001.png with the link text being the output of:
''{{Index2Name|0001}}''
Or if you use:
[[Image:Big-001.jpg|link=Articles/{{Index2Name|0001}}]]
The image, when clicked, will redirect you to the output of:
{{Index2Name|0001}}
I'm trying to restaurant names from Tripadvisor with Python 3 & lxml. The text i'm trying to retrieve is in the following element and is named 'Al Fresco's in this case.
<a target="_blank" href="/Restaurant_Review-g293925-d8327527-Reviews-
Al_Fresco_s-Ho_Chi_Minh_City.html" class="property_title"
onclick="ta.restaurant_list_tracking.clickDetailTitle('/Restaurant_Review-
g293925-d8327527-Reviews-Al_Fresco_s-
Ho_Chi_Minh_City.html','tags_category_tag_restaurants','8327527','1','0');">
Al Fresco's
</a>
The Xpath reference to this element:
//*[#id="eatery_8327527"]/div[2]/div[1]/div[1]/a
I use the following simple code to retrieve the text in this element:
from lxml import html
import requests
page = requests.get('https://www.tripadvisor.nl/Restaurants-g293925-
Ho_Chi_Minh_City.html')
tree = html.fromstring(page.content)
#This will create a list of Names:
Name = tree.xpath('//*[#id="eatery_8327527"]/div[2]/div[1]/div[1]/a/text()')
print ('Name: ', Name)
This returns me an empty array: Name: []
How do I get the text I want?
Without having a look at the actual page your Xpath is probably too strict. Try something like this:
//a[contains(#href,"Restaurant_Review")]/text()
If that yields too many results try adding the parent in front.
Hope that helps.
UPDATE:
After having a look at the actual page, this i probably what you are looking for:
//a[contains(#class,"property_title")]/text()
What is the best way to extract data from a table from an url?
In short I need to get the actual data from the these 2 tables at: http://www.oddsportal.com/sure-bets/
In this example the data would be "Paddy power" and "3.50"
See this image:
(Sorry for posting image like this, but I still need reputation, i will edit later)
http://img837.imageshack.us/img837/3219/odds2.png
I have tried with Jsoup, but i dont know if this is the best way?
And I can't seem to navigate correctly down the tables, I have tried things like this:
tables = doc.getElementsByAttributeValueStarting("class", "center");
link = doc.select("div#col-content > title").first();
String text1 = doc.select("div.odd").text();
The tables thing seem to get some data, but doesn't include the text in the table
Sorry, man. The second field you want to retrieve is filled by JavaScript. Jsoup does not execute JavaScript.
To select title of first row you can use:
Document doc = Jsoup.connect("http://www.oddsportal.com/sure-bets/").get();
Elements tables = doc.select("table.table-main").select("tr:eq(2)").select("td:eq(2)");
System.out.println(tables.select("a").attr("title"));
Chain selects used for visualization.