I have a question about decoding and Cypress.
On a test website, it is possible for a user to sort a table by a specific column via a URL: https://www.example.com/Search?text=blabla&maxrowcount=20&orderby=abc+def. The sort column is called "abc def" and consists of two words. The URL then says "abc+def". After the user has called the URL via GET, the URL https://www.example.com/Search?text=blabla&maxrowcount=100&orderby=abc%20def is embedded on the new page. maxrowcount is now 100.
When I test this with Cypress, the test will pass
let orderby='abc def'
cy.get("#new-link-maxrowcount-100").invoke('attr', 'href').then(href => {
const urlParams = new URLSearchParams(href);
cy.expect(urlParams.get('orderby')).to.equal(orderby);
});
With orderby='abc%20def' the test fails.
Is it correct that Cypress always decodes the text and then tests it?
P.S.
The web page was created just because of this question. It will never go online.
What I try to do is to loop through an array of Facebook page IDs and to return the code from each event page. Unfortunately, I only get the code of the last page ID in the array but as many times as elements are in the array. E.g. when I have 3 ID's in the array I get 3 times the code of the last page ID.
I already experimented with async await but I had no success.
The expected outcome would be the code of each page.
Thank you for any help and examples.
//Looping through pages
pages.forEach(
function(page) {
//Creating URL
let url = "https://mbasic.facebook.com/"+page+"?v=events";
//Getting URL
driver.get(url).then(
function() {
//Page loaded
driver.getPageSource().then(function(result) {
console.log(result);
});
}
);
}
);
you faced the same issue i did when i created a scraper using python and selenium. Facebook has countermeasure on manual URL change, you cannot change it , i receive the same data again and again even though it was automated. in order to get a good result you need to have access of face books Graph API which provides a complete object of Facebook page with its pagination URL.
or the second way i got it write was i used on click button of selenium browser automation to scroll down the next page.it wont work like you are typing , i prefer the usage of graph API
This is code I am using to get the reviews of Sephora webpage.
My problem is I want to get the reviews in the webpage https://www.sephora.com/product/crybaby-coconut-oil-shine-serum- P439093?skuId=2122083&icid2=just%20arrived:p439093
I want to inspect the webpage ,go to network tab to check through all the request and find which url is returning my data.
I am not able to find the url which is returning the reviews.
from selenium import webdriver
chrome_path = (r"C:/Users/Connectm/Downloads/chromedriver.exe")
driver = webdriver.Chrome(chrome_path)
driver.implicitly_wait(20)
driver.get("https://www.sephora.com/product/crybaby-coconut-oil-shine-
serum- P439093?skuId=2122083&icid2=just%20arrived:p439093")
reviews = driver.find_element_by_xpath('//*[#id="ratings-
reviews"]/div[4]/div[2]/div[2]/div[1]/div[3][#data-comp()='Elipsis Box'])
print(reviews.text)
In the string you pass to driver.get() you have a white space that should not be there...
The correct string should be:
driver.get("https://www.sephora.com/product/crybaby-coconut-oil-shine-serum-P439093?skuId=2122083&icid2=just%20arrived:p439093")
I am trying to scrape the resulting page from this page:
http://data.philly.com/philly/property/
I am using 254 W Ashdale St as my trial entry, when I do that in my browser it directs me to the result I'm looking for in the HTML (same URL though).
Python requests is successfully putting the address I put in in the results page, but I am not able to get the owner information, which is what I am trying to scrape. I have been trying with Selenium and phantomjs, nothing I am doing is working.
I was also confused about the form action, it seemed to just be the same URL as the page the form is on.
I appreciate any and all advice or help!
Selenium takes care of virtually everything, just find the elements, enter the information, find the button, click on it, then go to the owner, click on it and get scrap the info you need.
import selenium
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://data.philly.com/philly/property/')
#enter the street address
driver.find_element_by_name('LOC').send_keys('254 W Ashdale St')
#click on the submit button
driver.find_element_by_name('sendForm').click()
#find the owner
owner_tag = driver.find_elements_by_tag_name('td')[2]
owner = driver.find_elements_by_tag_name('td')[2].text
print(owner)
#click on the owner
owner_tag.find_element_by_tag_name('a').click()
#get the table with the relevant info
rows = driver.find_element_by_tag_name('tbody').find_elements_by_tag_name('tr')
#get the row with the sale prices
sale_prices = list()
for row in rows:
sale_prices.append(row.find_elements_by_tag_name('td')[4].text)
print('\n'.join(sale_prices))
Output:
FIRSTNAME LASTNAME
$123,600.00
$346,100.00
[..]
$789,500.00
Roblox is a game, and you can also make groups (Like Clans in other games).
I am making a program that goes through these group pages, and checks to see if they have an owner. If there is not an owner, then join the group to become the owner.
I am doing this to collect some data from non-owned groups.
Lastly, I'd like it to leave the group once the data is collected.
Here is the "Join Group" button:
<div id="ctl00_cphRoblox_JoinGroup" class="btn-neutral btn-large" onclick="__doPostBack('JoinGroupDiv', 'Click');" style="margin-top: 10px;">
Join Group
</div>
Here is the snippet of code I've tried:
import requests
s = requests.session()
Join_Group = dict('JoinGroupDiv', 'Click')
s.post('http://www.roblox.com/Groups/Group.aspx?gid=40', data=Join_Group)
I get the following error:
Traceback (most recent call last):
File "C:\Users\User\Desktop\Group.py", line 18, in <module>
Join_Group = dict('JoinGroupDiv', 'Click')
TypeError: dict expected at most 1 arguments, got 2
I'm pretty sure that I'm not supposed to be sending a Post request to the page, as to join the group, it does an onClick event.
EDIT 1:
Here is my updated code:
import requests
s = requests.session()
Join_Group = {"__EVENTTARGET":"ctl00_cphRoblox_JoinGroup", "__EVENTARGUMENT":"JoinGroupDiv"}
s.post('http://www.roblox.com/Groups/Group.aspx?gid=40', data=Join_Group)
But I don't quite know what to pass as the eventArguement. I don't get any errors, but when I load the page in Google Chrome it doesn't say I've tried to join.
EDIT 2:
I've also tried this:
import requests
s = requests.session()
Join_Group = {"__EVENTTARGET":"ctl00_cphRoblox_JoinGroup", "__EVENTARGUMENT":{"JoinGroupDiv","Click"}}
s.post('http://www.roblox.com/Groups/Group.aspx?gid=40', data=Join_Group)
EDIT 3:
So what I have here is the updated Join_Group with all of the necessary fields, but not all of the information. I don't know where to get the information.
Join_Group = {"__EVENTTARGET":"JoinGroupDiv", "__EVENTARGUMENT":"Click", "__LASTFOCUS":"", "__VIEWSTATE":"a lot of mumbo jumbo", "__VIEWSTATEGENERATOR":"It is 3D1CCC47 but that might change per post", "__EVENTVALIDATION":"some more mumbo jumbo"}
Here is a correct sample POST, but I don't know where it gets that information for __VIEWSTATE, __VIEWSTATEGENERATOR, and __EVENTVALIDATION.
__EVENTTARGET=JoinGroupDiv&__EVENTARGUMENT=Click&__LASTFOCUS=&__VIEWSTATE=fM9l9%2BTw8z%2FRNbMArorqQ7HQ2w3soDiNp5gJOc5sNNQPEzEzApHiWLOHghGcAriUGv6pCVCi15my4%2BUxUozLVQyGx%2Fiq%2FU9BxRdN80kWJgMyiIyZYtSnfsvlFkqmrHaLI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%2FBAZvHssrUeFA9OtAECcG4T3r68EB632IBprg8m9uiVX1wP%2BB8yQQdpQjBtYfT9rBHblz1HvaAu1mcRB0E%3D&ctl00%24cphRoblox%24GroupSearchBar%24SearchKeyword=Search+all+groups&ctl00%24cphRoblox%24rbxGroupRoleSetMembersPane%24dlRolesetList=2343447&ctl00%24cphRoblox%24rbxGroupRoleSetMembersPane%24RolesetCountHidden=2&ctl00%24cphRoblox%24rbxGroupRoleSetMembersPane%24currentRoleSetID=2343447&ctl00%24cphRoblox%24GroupWallPane%24GroupWallPager%24ctl01%24PageTextBox=1
EDIT 3:
s = requests.session()
login_data = dict(username='USERNAMEHERE', password='PASSWORDHERE')
s.post('https://www.roblox.com/newlogin', data=login_data)
page = s.get('http://www.roblox.com/Groups/Group.aspx?gid=403577')
soup=BeautifulSoup(page.content, "html.parser")
VIEWSTATE=soup.find(id="__VIEWSTATE")['value']
VIEWSTATEGENERATOR=soup.find(id="__VIEWSTATEGENERATOR")['value']
EVENTVALIDATION=soup.find(id="__EVENTVALIDATION")['value']
Join_Group = dict(__EVENTTARGET="JoinGroupDiv", __EVENTARGUMENT="Click", __LASTFOCUS="", __VIEWSTATE=VIEWSTATE, __VIEWSTATEGENERATOR=VIEWSTATEGENERATOR, __EVENTVALIDATION=EVENTVALIDATION)
join = s.post('http://www.roblox.com/Groups/Group.aspx?gid=403577', data=Join_Group)
print join
Your error is because this is not valid dict construction. You either need a literal (like {'foo': 'bar'}) or, if using the constructor, keyword arguments dict(foo='bar').
You should do a POST as that's what __doPostBack() does - post back to the same page/URL that's been served, see What is a postback?.
To determine what actually needs to be set for the POST, you should understand the __doPostBack() function.
Those arguments are used to populate hidden form fields called __EVENTTARGET and __EVENTARGUMENT.
You can read an explanation about this here:
http://www.codeproject.com/Articles/667531/doPostBack-function
Edit: It's also worth noting that, when interacting with an application in this manner, you also need to be aware of any other state that's being managed and passed to the server. There are cookies, viewstate etc. to be considered. It's best to go through the process in a browser and inspect/record the requests with the developer tools to help you determine what data is required.
Edit 2: I see that Roblox has an API. You're much better off using this if/where possible rather than interacting with their UI.
See http://wiki.roblox.com/index.php/Web_APIs#Group_APIs
If this isn't letting you get access to a list of groups (I don't see a search here at a glance) then you might consider a hybrid approach.
Edit 3: For the scraping-type approach, you may want to consider Beautiful Soup for parsing the page/form and extracting the values being added by ASP.NET -
http://www.crummy.com/software/BeautifulSoup/