Splinter- Web Scraping href by find_partial_text - web-scraping

I am new to web scraping and am trying to retrieve an href from an HTML page using Splinter and Beautiful Soup. Here is my code
# hem1
url="https://astrogeology.usgs.gov/search/map/Mars/Viking/cerberus_enhanced"
browser.visit(url)
hem1=browser.find_link_by_partial_text('Sample').get("href")
This receives the error
AttributeError: 'ElementList' object has no attribute 'get'
Any help is greatly appreciated.

You get this error because browser.find_link_by_partial_text('Sample') returns an ElementList. To get an element out of it, you need to use indexes.
Example:
hem1=browser.find_link_by_partial_text('Sample')
first_element = hem1[0]
To get the href you can use the below line:
hem1[0]['href']
More info about find_link_by_partial_text() : https://splinter.readthedocs.io/en/latest/api/driver-and-element-api.html#splinter.driver.DriverAPI.find_link_by_partial_text

Related

Cypress - Get a value form a dropdowm list

I'm new to Cypress and test automation in general.
I need to get a value from a dropdown list.
This is the html.
html
When trying to take the value of cypress, I get the following error:
error
I would greatly appreciate anyone who can guide me.

Why does my html request doesn't contain all elements displayed on my navigator?

I'm learning to scrape and I tried to scrape this booking page:
https://www.booking.com/searchresults.fr.html?label=gen173nr-1DCAEoggI46AdIM1gEaE2IAQGYAQ24ARjIAQzYAQPoAQGIAgGoAgS4Asn-2-kFwAIB&sid=a454e37209591e054b02e8917d61befe&sb=1&src=index&src_elem=sb&error_url=https%3A%2F%2Fwww.booking.com%2Findex.fr.html%3Flabel%3Dgen173nr-1DCAEoggI46AdIM1gEaE2IAQGYAQ24ARjIAQzYAQPoAQGIAgGoAgS4Asn-2-kFwAIB%3Bsid%3Da454e37209591e054b02e8917d61befe%3Bsb_price_type%3Dtotal%26%3B&ss=Paris&is_ski_area=0&ssne=Paris&ssne_untouched=Paris&dest_id=-1456928&dest_type=city&checkin_year=2019&checkin_month=7&checkin_monthday=28&checkout_year=2019&checkout_month=7&checkout_monthday=29&group_adults=1&group_children=0&no_rooms=1&b_h4u_keep_filters=&from_sf=1
While a curl command does not work (I got some error I don't understand...) I had to use a proxy service provider online via their API to make my request. This way, I get my html response but it doesn't contain prices and instead displays "voir les tarifs" buttons.
Can anyone explain to me why is it so ? I guess it has to do with script and dynamic displaying ...
Thank you for your time !

How do I send data to this checkbox using python with selenium web-driver

I am trying to automate this webpage and send some data to a checkbox with a dynamic #id.
I have used sample codes I found online but the test keeps failing due to not finding the element.
XPath for the webpage text box: //*[#id="undefined-Filter-undefined-24212"]
element:
In the snipped provided, the 24212 int is dymanic.
You can try something like and instead of name use x_path:
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
For reference : https://selenium-python.readthedocs.io/getting-started.html

Facebook Open Graph Story Determiner not working

I am trying to use 'the' as the article for my object, but FB is simply ignoring it and is using 'a' instead.
When I run the object's url in FB's debugger I see all the info that's necessary. All the other properties are being used just fine.
Anyone have any idea why this is happening?
Object types cannot use "the", only "a/an". So if your determiner isn't showing when not using the object's title, that's why.

Trying to add an achievement to a user but I get an error saying the achievement has og:type of 'website'

I've created and achievement:
https://graph.facebook.com/10150491734196645
It seems to be correct and there it says it is an achievement...
However when I try to add this achievement to an user i get the following error:
facebook.GraphAPIError: (#3502) Object at URL 10150491734196645 has
og:type of 'website'. The property 'achievement' requires an object of
og:type 'game.achievement'.
I don't know what I'm doing wrong here :/
It looks like is an error form FB, the og: properties have to be defined by the webpage FB visits. Probably you should create a middle-step and reproduce the data that is provided at https://graph.facebook.com/10150491734196645 in your server with that og:type 'game.achievement' type defined.
It was a stupid mistake, was passing the id of the achievement instead of the url!
https://graph.facebook.com/10150491734196645?&access_token=*******************
Create an access_token and use this.
For access_token;
https://smashballoon.com/custom-facebook-feed/access-token/

Resources