Comments (12)
Your solution is correct.
The problem of your first code is:
await page.goto("https://github.com")
await page.click('.HeaderMenu [href="/features"]') # start navigation to the feature page here
await page.waitForNavigation() # waiting for the "next" navigation from the feature page
To avoid this situation, you need to start click
and waitForNavigation
(almost) simultaneously, as your solution.
I will update document about page.click()
by the next release.
from pyppeteer.
You need to wait for page contents loaded.
Use waitForSelector
method before click.
print(await result_page.title())
await result_page.waitForSelector('a.ng-binding')
await result_page.click('a.ng-binding')
from pyppeteer.
Seems to have found a way to achieve, but I do not understand, do not know whether the correct, I hope to get your guidance, thank you
solution:
await asyncio.wait([page.click('.HeaderMenu [href="/features"]'), page.waitForNavigation()])
from pyppeteer.
sorry guys,i found the solution still not work in my case. any idea for this?
async def main():
browser = await launch({"headless":False})
page = await browser.newPage()
await page.goto('http://wsjs.saic.gov.cn')
await page.screenshot({'path': 'example.png'})
await page.click('#txnS02',{"waitUntil":"networkidle0"})
title = await page.title()
if title is None or title =="":
await page.reload({"waitUntil":"networkidle0"})
print (await page.title() + str(len(await browser.pages())))
await page.screenshot({'path': 'example1.png'})
await page.focus("input[name='request:sn']")
await page.type("input[name='request:sn']","26716759",{"delay": 50})
await page.screenshot({'path': 'example2.png'})
await asyncio.wait([page.click('#_searchButton'), page.waitForNavigation()])
print (await page.title())
# await browser.close()
asyncio.get_event_loop().run_until_complete(main())
from pyppeteer.
Since page.click
does not accept waitUntil
option, this line is incorrect.
await page.click('#txnS02',{"waitUntil":"networkidle0"})
So you need to use await asyncio.wait([page.click(...), page.waitForNavigation()])
here, too.
from pyppeteer.
Updated document of Page.click()
from pyppeteer.
actually it's working for me at that line ,but still got the Navigation Timeout Exceeded: 30000 ms exceeded at line await asyncio.wait([page.click('#_searchButton'), page.waitForNavigation()])
from pyppeteer.
Thank you for details.
I reproduced the error.
I will try to fix it.
from pyppeteer.
I understand the problem.
Since page.click('#_searchButton')
opens a new tab, navigation event is fired in the different page instance.
So you need to watch targetcreated
event on the browser.
Try the below code:
import asyncio
from pyppeteer import launch
async def main() -> None:
browser = await launch({"headless": False, "args": ['--no-sandbox']})
page = await browser.newPage()
await page.goto('http://wsjs.saic.gov.cn')
await page.screenshot({'path': 'example.png'})
await asyncio.wait([page.waitForNavigation(), page.click('#txnS02')])
title = await page.title()
if title is None or title == "":
await page.reload({"waitUntil": "networkidle0"})
print(await page.title() + str(len(await browser.pages())))
await page.screenshot({'path': 'example1.png'})
await page.focus("input[name='request:sn']")
await page.type("input[name='request:sn']", "26716759", {"delay": 50})
await page.screenshot({'path': 'example2.png'})
result_page_future = asyncio.get_event_loop().create_future()
browser.once('targetcreated',
lambda target: result_page_future.set_result(target))
await page.click('#_searchButton'),
result_page = await (await result_page_future).page()
print(await result_page.title())
# await browser.close()
asyncio.get_event_loop().run_until_complete(main())
output is:
商标综合检索2
商标检索结果
from pyppeteer.
hi bro, but seems i'm not able to click the link inside the table. Means if this page is dynamic loading how can i access the content?Thanks
import asyncio
from pyppeteer import launch
async def main() -> None:
browser = await launch({"headless": False, "args": ['--no-sandbox']})
page = await browser.newPage()
await page.goto('http://wsjs.saic.gov.cn')
await page.screenshot({'path': 'example.png'})
await asyncio.wait([page.waitForNavigation(), page.click('#txnS02')])
title = await page.title()
if title is None or title == "":
await page.reload({"waitUntil": "networkidle0"})
print(await page.title() + str(len(await browser.pages())))
await page.screenshot({'path': 'example1.png'})
await page.focus("input[name='request:sn']")
await page.type("input[name='request:sn']", "26716759", {"delay": 50})
result_page_future = asyncio.get_event_loop().create_future()
browser.once('targetcreated',
lambda target: result_page_future.set_result(target))
await page.click('#_searchButton')
result_page = await (await result_page_future).page()
print(await result_page.title())
await result_page.click("a.ng-binding") #it does not work
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
from pyppeteer.
Thank u bro!!
from pyppeteer.
Hi @miyakogi , could you give this post https://stackoverflow.com/questions/60763644/cant-go-on-clicking-on-the-next-page-button-while-scraping-certain-fields-from a shot in case there is any solution you would like to offer. The post that I created in there is about pyppeteer. Thanks.
from pyppeteer.
Related Issues (20)
- how to clear the input area?
- Page.cookies() returns List, not Dict HOT 1
- TypeError: 'coroutine' object is not callable, why? HOT 1
- Support ARM OS HOT 1
- Navigation Timeout Exceeded: 30000 ms exceeded HOT 7
- Error browser closes unexpectedly HOT 1
- Can I get innerHTML from the Element Handle Class? HOT 1
- Response.buffer() return str rather than [bytes] HOT 1
- Pyppeteer on python 3.6.8 HOT 1
- UTF-8 characters are coming as garbage HOT 1
- KeyError when send HOT 1
- SyntaxError: invalid escape sequence HOT 2
- Is pyppeteer still maintained? HOT 4
- --enable-automation HOT 1
- can we use the cookies in python request from puppeteer cookies? HOT 1
- Page goto returns None HOT 2
- Execution context was destroyed, most likely because of a navigation. HOT 2
- Is there a forum or something for specific question related to pyppeteer? HOT 1
- Screenshot is not working in headless HOT 1
- >> REPOSITORY ABANDONED >> use pyppeteer2 instead HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyppeteer.