当Google地图达到某个级别时,确认了一个地点搜索,它将其重定向到特定的Google Place URL,否则它将返回地图搜索结果页面。
Google Map搜索“ Manarama”是
https://www.google.com/maps/search/manarama/@23.7505522,90.3616303,15Z/Data=!4m2!2m1!6e6
,将其重新送给Google Place url
https://www.google.com/maps/place/Manarama,+29+Rd+No.+14A,+Dhaka+1209/@23.7505522,90.3616303 ,15z/data =!4m5!3m4!1S0X3755BF4DFC183459:0xB9127B8C3072C249!8M2!3D23.750523
!
4D90.3703851 =“ https://www.google.com/maps/search/mana/@24.211316,89.340686,8z/data=!3M1!4B1“ rel =“ nofollow noreferrer” /search/mana/@24.211316,89.340686,8z/data=!3M1!4B1
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto("https://www.google.com/maps/search/manarama/@23.7505522,90.3616303,15z/data=!4m2!2m1!6e6", wait_until="networkidle")
print(page.url)
await page.close()
await browser.close()
asyncio.run(main())
有时它会返回重定向的URL,但大多数情况下,它不是。怎么知道URL肯定会重定向到一个位置URL?以下stackoverflow帖子具有相似之处,但不能使它适合我的情况
如何使用playwright使用WebApp捕获重定向
when Google Map is to some level confirmed about a place search it redirects to the specific Google place url otherwise it returns a map search result page.
Google Map search for "manarama" is
https://www.google.com/maps/search/manarama/@23.7505522,90.3616303,15z/data=!4m2!2m1!6e6
which redirects to a Google Place URL
https://www.google.com/maps/place/Manarama,+29+Rd+No.+14A,+Dhaka+1209/@23.7505522,90.3616303,15z/data=!4m5!3m4!1s0x3755bf4dfc183459:0xb9127b8c3072c249!8m2!3d23.750523!4d90.3703851
Google Map search result page looks like the following link below when it is not confirmed about the specific place
https://www.google.com/maps/search/Mana/@24.211316,89.340686,8z/data=!3m1!4b1
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto("https://www.google.com/maps/search/manarama/@23.7505522,90.3616303,15z/data=!4m2!2m1!6e6", wait_until="networkidle")
print(page.url)
await page.close()
await browser.close()
asyncio.run(main())
Sometimes it returns the redirected URL, but most of the time, it doesn't. How to know the URL got redirected to a place URL for sure? the following StackOverflow post has similarities but couldn't make it work for my case
How to catch the redirect with a webapp using playwright
发布评论
评论(1)
您可以使用 nofollow noreferrer“> expect_navigation 。
在您提到的有关与该功能匹配的URL的评论中。几乎所有这样的剧作家功能都接受 regex 模式。因此,如有疑问,只需使用正则。请参阅下面的代码:
为了检查页面是否导航,只需在
中包装函数。 )到
期望_navigation
。然后,如果提出了超时
错误,您知道没有任何与我们模式相匹配的URL更改。You can use expect_navigation.
In the comments you mentioned about what url to match for with the function. Almost all such playwright functions accept regex patterns. So when in doubt, just use regex. See the code below:
In order to check whether the page navigated or not, just wrap the function inside a
try..except
block and pass a suitabletimeout
argument (in ms) toexpect_navigation
. Then if aTimeout
error was raised, you know that there wasn't any url change which matched our pattern.