XPath Next Page navigation - xpath

I'm using Chrome Data Miner, and so far, failing to extract the data from my query: http://www.allinlondon.co.uk/restaurants.php?type=name&rest=gluten+free
How to code the Next Element Xpath for this website? I tried all the possible web sources, nothing worked.
Thanks in advance!

You could look for a tags (//a) whose descendant::text() starts with "Next" and then get the href attribute of that a element.
% xpquery -p HTML '//a[starts-with(descendant::text(), "Next")]/#href' 'http://www.allinlondon.co.uk/restaurants.php?type=name&rest=gluten+free'
href="http://www.allinlondon.co.uk/restaurants.php?type=name&tube=0&rest=glutenfree&region=0&cuisine=0&start=30&ordering=&expand="

Related

Following sibling doesn't work on google search

I am trying to write my own Xpath using following sibling concept on Google Search page and trying to select "Google Search" button on that but when I check my Xpath in Firefox console it isn't able to identify the element.
I tried by removing following sibling tag and it worked but it doesn't work when I use following-sibling tag.
This works -
$x("//div[#id='searchform']/form/div[2]/div/div[3]/center/input[1]")
This is what I am using in console.
This doesn't work -
$x("//div[#id='searchform']/form/div[2]/div/following-sibling::div[2]/center/input[1]")
I am expecting it to highlight "Google Search" button but it isn't recognizing that.
"x/following-sibling::y" looks for a sibling of type "y" of type "x" element.
/div/div[3]/center looks for third div child of first div element,
but /div/following-sibling::div[2]/center looks for second div sibling of first div element and not child of it as in first case, which fails.
So in your case,
$x("//div[#id='searchform']/form/div[2]/div/div/following-sibling::div[2]/center/input[1]")
should work for you.

why can not i get the data from this URL?

There are some data on this page :
$ scrapy shell "https://partsouq.com/en/catalog/genuine/unit?c=Toyota&ssd=%24HQwdcgcAAwFNa3YjVR92aVB7C10ZDko%24&vid=4463&cid=&uid=2535&q="
and there are numbers on the left hand-side of the page, After clicking on any one of them a table with contents appears like in the attachement, but after making "inspect element" on any item on this table, i get empty set !!
response.xpath('//*[#id="gf-result-table"]/tr[2]/td[2]/div').extract()
[ ]
this shows the tabe and the html code for it
You are giving wrong xpath. correct xpath is
response.xpath('//*[#id="gf-result-table"]/tbody/tr[2]/td[2]/div')
https://partsouq.com/en/search/search?q=0910112012&qty=1
this is the url of the attachement, the pop-up window is rendered by JavaScript, you can not do JS things in the scrapy.
And the xpath for the a tag is simple:
//a[#id]

How to write xpath for below code displayed on Image

Snapshots displayed Field as well as Inspect element code. Always faced problem on writing xpath for table element. Xpath copied from Moxilla firbugs is worked sometimes but not always.. can any one tell how to write xpath of above code.... Thanks
You can use this xpath
//table[#class='detailList']/tbody/tr/td[contains(text(),'Business Lease')]

How to locate an element having href='#' attribute in anchor tag

abc
I am not able to locate above element. I tried //*[#id="contact-groups"], but with no success.
Well, XPath is not the best of the methods to find elements. But following will match the links with href = "#".
//a[#href="#"]
Not sure if your scenario is as simple as your question. I did test this with a simple html page.
The locator seems correct. You could try this too:
.//*[#id='contact-groups']
As per HTML code provided you can try below xpaths
//a[#id='contact-groups']
//a[contains(text(),'abc')]
//a[#href='#']
Thanks
I am guessing the link is in an Iframe.
Use the following code to switch to the frame and then click on the link
driver.switchTo().frame("frame-name");
driver.findElement(By.xpath("//a[#id='contact-groups']")).click();

XPath Expression

I am new to XPath. I have a html source of the webpage
http://london.craigslist.co.uk/com/1233708939.html
Now I want to extract the following data from the above page
Full Date
Email - just below the date
I also want to find the existence of the button "Reply to this post" on the page
http://sfbay.craigslist.org/sfc/w4w/1391399758.html
Can anyone help me in writing the three XPath expressions for the above three data.
You don't need to write these yourself, or even figure them out yourself. If you use the Firebug plugin, go to the page, right click on the elements you want, click 'Inspect element' and Firebug will popup the HTML in a viewer at the bottom of your browser. Right click on the desired element in the HTML viewer and click on 'Copy XPath'.
That said, the XPath expression you're looking for (for #3) is:
/html/body/div[4]/form/button
...obtained via the method described above.
I noticed that the DTD is HTML 4/01 Transitional and not XHTML for the first link, so there's no guarantee that this is a valid XML document, and it may not be loaded correctly by an XML parser. In fact, I see several tags that aren't properly closed (i.e. <hr>, etc)
I don't know the first one off hand, and the third one was just answered by Alex, but the second one is /html/body/a[0].
As of your first page it's just impossible to do because this is not the way xpath works. In order for an xpath expression to select something that "something" must be a node (ie an element)
The second page is fairly easy, but you need an "id" attribute in order to do that (or anything that can make sure your button is unique). For example if you are sure the text "Reply to this post" correctly identify the button just do it with
//button["Reply to this post"]

Resources