截图从列表改为单个, 修改发帖定位和获取帖子链接的操作, 打开url可能白屏多打开一次url
This commit is contained in:
2
const.py
2
const.py
@@ -19,7 +19,7 @@ ELEMENT = {
|
||||
ENDPOINT = "154.19.186.49"
|
||||
ACCESS_KEY = '3QcjsqdCYCoy1khuDqia'
|
||||
SECRET_KEY = 'iPXte32y1deoySiDq0RwONUJIiIgvjTVhbfCL8tV'
|
||||
BUCKET = 'facebook'
|
||||
BUCKET = 'test'
|
||||
|
||||
# DOVE PROXY
|
||||
DOVE_USER = 'fetdog'
|
||||
|
||||
@@ -830,6 +830,8 @@ def playwright_like(cookies, target_url):
|
||||
page = context.new_page()
|
||||
url = 'https://facebook.com'
|
||||
try:
|
||||
page.goto(url)
|
||||
time.sleep(1)
|
||||
page.goto(url)
|
||||
check_account_status(page)
|
||||
|
||||
@@ -859,7 +861,7 @@ def playwright_like(cookies, target_url):
|
||||
put_object(key, screenshot_content)
|
||||
return {
|
||||
'response_url': target_url,
|
||||
'screenshot_key': [key]
|
||||
'screenshot_key': key
|
||||
}
|
||||
|
||||
|
||||
@@ -878,6 +880,8 @@ def playwright_post(cookies, content, image_key=None):
|
||||
page = context.new_page()
|
||||
url = 'https://facebook.com'
|
||||
try:
|
||||
page.goto(url)
|
||||
time.sleep(1)
|
||||
page.goto(url)
|
||||
check_account_status(page)
|
||||
time.sleep(5)
|
||||
@@ -897,16 +901,16 @@ def playwright_post(cookies, content, image_key=None):
|
||||
if not image_key:
|
||||
page.click('''//span[contains(text(), "What's on your mind")]''')
|
||||
_edit_privacy(page)
|
||||
page.type('''//div[contains(@aria-label, "What's on your mind")]''', content)
|
||||
page.type('''//div[contains(@aria-placeholder, "What's on your mind")]''', content)
|
||||
|
||||
page.click('//div[@aria-label="Post"]')
|
||||
time.sleep(15)
|
||||
|
||||
post_url = page.locator('//div[@data-pagelet="FeedUnit_0"]//a[@role="link"]').nth(2).get_attribute('href')
|
||||
if '&__cft__' in post_url:
|
||||
post_url = post_url.split('&__cft__')[0]
|
||||
page.goto(post_url)
|
||||
post_index = page.locator('//div[@aria-posinset="1"]//a[@role="link"]').nth(2)
|
||||
post_index.click()
|
||||
time.sleep(5)
|
||||
page.reload()
|
||||
post_url = page.url
|
||||
|
||||
except Error as e:
|
||||
raise OperationFailed(f'操作超时,请重试{e}')
|
||||
|
||||
@@ -918,7 +922,7 @@ def playwright_post(cookies, content, image_key=None):
|
||||
|
||||
key = f'{uuid.uuid4()}.png'
|
||||
put_object(key, screenshot_content)
|
||||
return {'response_url': post_url, 'screenshot_key': [key]}
|
||||
return {'response_url': post_url, 'screenshot_key': key}
|
||||
|
||||
|
||||
def playwright_comment(cookies, target_url, content, image_key=None):
|
||||
@@ -992,7 +996,7 @@ def playwright_comment(cookies, target_url, content, image_key=None):
|
||||
put_object(key, screenshot_content)
|
||||
return {
|
||||
'response_url': target_url,
|
||||
'screenshot_key': [key]
|
||||
'screenshot_key': key
|
||||
}
|
||||
|
||||
|
||||
@@ -1011,10 +1015,14 @@ def playwright_get_user_profile(cookies, username=None):
|
||||
page = context.new_page()
|
||||
url = 'https://facebook.com'
|
||||
try:
|
||||
page.goto(url)
|
||||
time.sleep(1)
|
||||
page.goto(url)
|
||||
check_account_status(page)
|
||||
|
||||
profile_pic_url = page.locator('//div[@aria-label="Shortcuts"]//li[1]//*[@preserveAspectRatio="xMidYMid slice"]').get_attribute('xlink:href')
|
||||
profile_pic_url = page.locator(
|
||||
'//div[@aria-label="Shortcuts"]//li[1]//*[@preserveAspectRatio="xMidYMid slice"]').get_attribute(
|
||||
'xlink:href')
|
||||
username = page.locator('//div[@aria-label="Shortcuts"]//li[1]//span').first.inner_text()
|
||||
except Error as e:
|
||||
raise OperationFailed(f'操作超时,请重试{e}')
|
||||
@@ -1023,7 +1031,8 @@ def playwright_get_user_profile(cookies, username=None):
|
||||
|
||||
response = requests.get(
|
||||
url=profile_pic_url,
|
||||
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'},
|
||||
headers={
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'},
|
||||
# proxies={
|
||||
# 'http': 'http://127.0.0.1:10889',
|
||||
# 'https': 'http://127.0.0.1:10889',
|
||||
@@ -1055,6 +1064,8 @@ def playwright_set_user_profile(cookies, username=None, first_name=None, last_na
|
||||
page = context.new_page()
|
||||
url = 'https://www.facebook.com'
|
||||
try:
|
||||
page.goto(url)
|
||||
time.sleep(1)
|
||||
page.goto(url)
|
||||
check_account_status(page)
|
||||
|
||||
@@ -1120,6 +1131,8 @@ def playwright_check_account_cookies(cookies):
|
||||
page = context.new_page()
|
||||
url = 'https://www.facebook.com'
|
||||
page.goto(url)
|
||||
time.sleep(1)
|
||||
page.goto(url)
|
||||
time.sleep(10)
|
||||
check_account_status(page)
|
||||
context.close()
|
||||
@@ -1165,4 +1178,3 @@ if __name__ == '__main__':
|
||||
# # image_key='rg.jpg'
|
||||
# )
|
||||
# playwright_check_account_cookies(cookies)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user