How to replicate this javascript onclick using requests? - python-3.x

I have this button in a website:
<a data-page-number="6" data-offset="150" href="website.com/etc.html" class="pageNum taLnk" onclick=" require('common/Radio')('restaurant-filters').emit('paginate', this.getAttribute('data-offset'));; ta.trackEventOnPage('STANDARD_PAGINATION', 'page', '6', 0); return false;
">
6
</a>
The website shows a list, and to move to page list 1,2,3,etc.. you have to click on the above button, the data-offset is what controls which page list the website is showing.
I want to replicate clicking on this button using requests, is that possible?

i was able to send the "data-offset" attribute manually by using this code
requests.get('url', params={"data-offset":"2220"}).text

Related

Not able to click on specific print button in IE using VBA

I am trying to click on a print button on a specific web page, but cannot figure out the correct VBA code.
This is the print portion of my code:
With IE
.Document.querySelector("[data-testid='moreActionsButton']").Click
.Document.querySelector("[data-testid='createPdfButton']").Click
.Document.querySelector("[data-testid='detailed-button']").Click
.Document.querySelector("[data-testid='download-pdf-button']").Click
End With
This is the code on the web page for the button I am trying to click:
<div class="PdfForm__ButtonBar-sc-1h3mt9w-0 bjYOJP">
<button class="Button-sc-19jm674-2 kWKZnE"
data-testid="createPdfButton" variant="success"
type="submit">Download PDF</button>
</div>
Please note the the print options are in a pop-up so submit does not work. I also tried doing another query selector by as you can see the testid is the same as another step. Everything works up to this point.

How to scrape a page and then perform a button click to go to next page for scraping using Selenium and BeautifulSoup

I am scraping a web page which has a table with child tr and td tags. I am able to scrape the first page properly. But to go to the next page I need a button click. I need some help in understanding that. I am using Selenium and Beautiful soup to get the page response.
The html for the button tag is as follows:
<input type="submit" name="RadGrid1$ctl00$ctl03$ctl01$ctl28" value=" " onclick="return false;" title="Next Page" class="rgPageNext">
The sample code that I have tried:
for i in range(0,14):
# code for scraping 1 page
some code here
btn = driver.find_element_by_xpath(xpath)
btn.click()
The button click goes to the next page but is not able to scrape info for any of the 2-14 pages. I have tried putting my scraping 1 page code in a for loop and added the button click logic at the end. It scrapes 1st page, performs a button click but doesn't go through to the next page. Instead it loops back to page 1.
As to what I can understand, I think you haven't updated the new url to the Beautifulsoup. After the click you take the current url of the new page and then perform scraping. Then only it will scrape the new page otherwise it contains the url of the old page and thus scrapes that page only.

Chrome extension - wait popup until script is done

I am trying to make a Chrome extension, everything is going well, except that before the content of the popup is filled with javascript(XMLHttpRequest - asynchronous) I see a small blank popup that has not yet been filled.
That is,
Before this loads
I see this
In the code, I am simply using document.getElementById to fill up the HTML. So it looks like
HTML:
<body>
<div id="status"></div>
</body>
JS:
document.getElementById('status').innerHTML = 'content of the request';
I see where this is coming from, since the popup is originally blank it shows that little blank box before javascript(XMLHttpRequest) is done. But How can I make it wait until the request is complete?
You can't manually display the browser/page action popup. This feature will not be implemented : source.
The most simple solution is to add a loading wheel gif to the html of the popup. It will display the popup until the content is changed by your code when the request is complete.
Another solution is to display a popup (not a browser/page action popup) when the user click on the browser/page action. This way you can wait for the request to display your popup.

How to click on link element with specific text using watir?

I'm not able to click on text link 'Add' using watir:
PAGE:
<div id="divAdd" style="float: right">
<a onclick="SwitchView('2')" style="color: #1B56A7; cursor: pointer;">Add</a>
</div>
Watir CODE:
browser.link(:text =>"Add").click
EXCEPTION:
Unable to locate element, using {:tag_name=>["a"], :text=>"Add"}
Please help me how to handle this?
If the page has a lot of ajax and javascript going on, you may just have to wait a little bit for the client side code to finish rendering the page after it has been loaded from the browser.
Try this
browser.link(:text =>"Add").when_present.click
If that does not work, then make sure the item is not in a frame or something..
btw, if there is more than one link on the page with the text 'Add' then you may have to specify a container outside the link that lets you identify which link you want. eg.
browser.div(id: => "divAdd").link.when_present.click
If
This would be my way of doing it.
while browser.div(:class, 'containerDIV').a(:text, 'Add').exists? do
browser.div(:class, 'containerDIV').a(:text, 'Add').click
end

Watir :- click an image button?

I have am using firefox and i have modified its user agent to make it behave like iphone web browser. now when i open google.com using watir and now i want to click on the searh button which is an image in mobile view. how to do that.
To click an image
<img id="logo">
try this
browser.image(:id => "logo").click
If the image is actually a button
<input type="image" id="logo">
try this
browser.button(:id => "logo").click
The next time please provide relevant HTML.
Also, take a look at HTML Elements Supported by Watir page.

Resources