async def pyChrome(self):
if '--enable-automation' in launcher.DEFAULT_ARGS:
launcher.DEFAULT_ARGS.remove("--enable-automation")
browser = await launch(
{'handleSIGINT': False, 'handleSIGTERM': False, 'handleSIGHUP': False},
headless=False, dumpio=True, userDataDir=r'./text',
args=['--no-sandbox', '--disable-setuid-sandbox', '--disable-blink-features=AutomationControlled'])
page = await browser.newPage()
await page.setViewport({ # 最大化窗口
"width": 1600,
"height": 800
})
try:
await page.setUserAgent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Mobile Safari/537.36")
url = 'https://www.espn.com/watch/schedule/_/type/live/country/us/redirected/true'
await page.goto(url, {'waitUntil': ['load', 'domcontentloaded', 'networkidle0']})
# await page.waitForNavigation()
await page.click('button.Button--unstyled')
li = await page.xpath('//ul[@class="Nav__Dropdown__Menu__List flex-expand"]/li')
if len(li)<=7:
await li[6].click()
await page.waitFor(3000)
pframes = page.frames
for i in pframes:
for j in i.childFrames:
con = await j.xpath('//div[@class="content ng-scope"]')
if con:
user = await con[0].xpath('//input[@type="email"]')
pwd = await con[0].xpath('//input[@type="password"]')
submit = await con[0].xpath('//button[@type="submit"]')
await user[0].type('1111111')
await pwd[0].type('1111111')
await submit[0].click()
frame嵌套的可以通过childFrames查找嵌套的子frame