In part of a web page, I currently link to a part of the webpage using . In other words, I link to something like:
Link 1
However, on that same link I want to include a PHP variable, which would normally look like
Link 2
Combining the two in either order just makes the page refresh, neither scrolling properly or taking the php variable. How can I use the two simultaneously?
You can concatenate the two together, just put the hash last because that is not sent to the webserver (it will be used by the browser to jump to a certain part of the page):
Link 1
When you're on the same page as the URL in your anchor, regardless of #'s value (It's called the "fragment"), the page won't even refresh, it will scroll up in hope to find an anchor that has the fitting name for the fragment
The URL fragment (everything behind # at the end of an URL) is a client-side thing, PHP won't be able to do anything with it
Related
Say I have an anchor somewhere on a different page:
<A NAME="blah">
On the page I'm currently on, I want to go that that anchor on that different page while also passing a GET parameter, such as, for example:
Good Stuff!
This doesn't seem to be working for me. It loads the page and passes the variable but doesn't go to the anchor. I've searched for examples on the anchor tag, and there's tons of them, but nobody talks about jumping to an anchor in a page while also passing parameters in the URL.
The bookmark always goes last.
Good Stuff!
I'm using http://simplemvcframework.com and I want to link to a section on a page normally you will just add something link
#section4
to the end of the URL but this doesn't work as expected, it doesn't jump to the correct section of the page. I'm suing the following format to try and achieve this:
/controller#section4
Do I need to pass the view into the link somehow? possibly something along the lines of
/controller/viewname.php#section4
I have never used that framework before, but anchors are handled by the browser, and don't even get sent to the browser.
(I.e. when accessing /controller/#section4, the server only receives /controller/.)
It looks like you don't know about the actual use of # in URLs:
Upon loading the page, the browser will look for an element on that page with an id or name (for backwards compatibility) matching the part after the #.
So you probably just want an element with id="section4" on that page.
If you need HTML 4 support, you have to put <a name="section4">...</a> around your anchor to achieve the same effect.
(See also this question.)
I want to load pages from PeoplePerHour.com into python to run some data analysis, but it keeps getting data from a page I didn't ask for, I think it must go to the main page and then refreshes somehow into the page I ask for.
For example:
I want to pull the prices from all users at http://www.peopleperhour.com/freelance/data+analyst, and the data spans over multiple pages.
Say I want to request page 2, http://www.peopleperhour.com/freelance/data+analyst#page=2. If I go here in a browser, it works fine and pulls up page 2, but I think it pulls up page one first and then "refreshes" into page 2 (I think). If I access this in python, it loads the HTML from the first page, and never sees page 2.
Here's my code:
import requests
from pattern import web
import re
import pandas as pd
def list_of_prices(url):
html = requests.get(url).text
dom = web.DOM(html)
list = []
for person in dom('.freelancer-list-item .medium.price-tag'):
currency = person('sup')
amount = person('span')
list.append([currency[0].content if currency else 'na', amount[0].content if amount else 'na'])
return list
list_of_prices('http://www.peopleperhour.com/freelance/data+analyst#page=2')
No matter what, this returns the prices from page 1.
What is going on that I'm just not seeing?
If I understand correctly, you want to iterate through the pages. If that's the case, I believe the problem is with your URL.
Here's the URL you gave:
http://www.peopleperhour.com/freelance/data+analyst#page=2
The problem is, "page" is not a bookmark on that page. When you use the #page=2, it tells the browser to go down to the same page for a bookmark called "page=2".
Here's the URL for the Next button in that site:
http://www.peopleperhour.com/freelance/data+analyst?sort=most-relevant&page=2
You'll see it says "&page=2" which means something else. In their code "page" is a variable being passed via the url, with a value of 2. You use the "&" if there are more than one of these variables. Also, you are missing a "?" symbol. If you're passing variables via the URL, you have to put a ? followed by the name=value pairs for your variables.
So, easy fix, change your url to this:
http://www.peopleperhour.com/freelance/data+analyst?page=2
That's in comparison to your old url:
http://www.peopleperhour.com/freelance/data+analyst#page=2
As a quick test, copy/paste the corrected url on your web browser. You will see it now is on page 2.
Getting dynamic content (those generated by client-side code) is always very tricky. There is no easy solution to this, but if you really want to dig into it, I recommend PyV8, a JavaScript engine in Python.
Error in pattern when using pattern3 in python 3.6
Please click on the above Hyperlink to open the Image
What is the alternative to executing the same code under python3.6 environment because due to this I have to install the pattern3, the pattern is not supported by the python 3.6
Thanks!
I have a forum whereby links to a thread looks like
http://www.website.com/comments.php?topic_id=1
How can I make it look like this
http://www.website.com/1046302/some-link-desc#12154109
so that when such links are given out, the user is taken directly to that particular comment.
I'm particular about the #12154109 . The other part of the URL /1046302/some-link-desc is achieved through .htaccess configuration.
Question Update
What is the best way to get the unique number ? Do I use a timestamp or a concatenation of the topic_id and comment_id ?
You would have to apply a the following tag in the comment portion of your template.
<a name"1215409"></a>
of course the number would be set to the comment id.
You're not going to be able to do this through htaccess. The fragment, the #something part of the URL, tells the client specifics on how to handle the content that it was served, in the case of anchors, it tells the browser where to seek to in the page. The fragment is never sent to the server, so apache never sees it, and thus nothing in the htaccess file can match against it or use it in any way.
Fragments are also used by javascript which can look at the URL to pull stuff out of the fragment or to force a script to rerun by reloading the page with a different fragment.
You can, however, send fragments to the client from the server, but there's no way to know whether the client already has the fragment or not. But the content itself will need to have the fragments in the links, htaccess isn't going to know which anchors are in the actual content that ends up being served.
Here's the situation.
I have a site where clicking hyperlinks within a certain div makes a jQuery function get the content of a div from a separate page. Because of this, the URL don't change. I need it to change as well as writing an entry in history.
My pages are setup like this (not sure this is the smartest way of going though)
access.php (main logon)
new-user.php
forgot-pass.php
index.php
controlpanel.php
etcetc. Now, all of these pages are reachable on their own and are mainly identical and all contain a div called "container". When clicking links, the content from this div gets erased and the content from the coresponding div (container) gets loaded from the file of the URL (href). I'm terrible at explaining..
So basically, what I need is some javascript that picks up the href link address and just pastes it in the url bar at the same time as it creates an entry in history so the back and forth buttons work.
I plan on extending this in a while as well, translating query strings as well. But there are a few constant static pages I need to take care of first. Any help would be very appreciated! :)
You are not allowed to change the entire URL by JavaScript but you can use URL hashes. I recommend you the browser history plug-in. You can simply register a handler to react on URL changes and load your corresponding content via ajax.
Have you looked at the jquery address plugin? Look at the examples. Is this similar to what you want?
It's not possible with "normal urls" (we must wait for a new generation of browsers...)
But there is a "trick": playing with anchors.
A link like "same_page.php#anchor" does not reload the page, but act on both the history and the adress bar.
So, if instead of having url like "page.php?param=lorem", you could have "page.php#param=lorem", you have your solution :)