阿里滑块

This commit is contained in:
luzhisheng 2024-07-18 02:43:01 +08:00
parent bc4c5c5df6
commit 2f6a227430
2 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,63 @@
from DrissionPage import ChromiumPage, ChromiumOptions
import json
import time
import re
import random
import datetime
class Detail(object):
def __init__(self):
co = ChromiumOptions()
co.auto_port()
self.page = ChromiumPage(co)
self.page.listen.start('https://detail.1688.com/offer/643272204627.html')
def slide(self):
"""
滑动代码
:return:
"""
ele = self.page.wait.eles_loaded("x://span[contains(@id,'nc_1_n1z')]", timeout=20)
if ele:
ele = self.page.ele("#nc_1_n1t")
time.sleep(3)
ele.hover()
self.page.actions.hold('#nc_1_n1z')
self.page.actions.move(100, duration=random.random())
self.page.actions.move(100, duration=random.random())
self.page.actions.move(59, duration=3)
def request_body(self):
url = 'https://detail.1688.com/offer/643272204627.html'
self.page.get(url)
res = self.page.listen.wait()
pattern = r'window\.__INIT_DATA\s*=\s*(\{.*?\})\s*</script>'
match = re.search(pattern, res.response.body)
try:
json_data = match.group(1)
dict_data = json.loads(json_data)
temp_model = dict_data.get('globalData').get('tempModel')
print(datetime.datetime.now())
print(temp_model)
except Exception as e:
print(e)
self.slide()
if self.page.wait.eles_loaded("#recyclerview"):
print('过滑动成功')
elif self.page.wait.eles_loaded("#nc_1_refresh1"):
print('滑动失败')
# 需要继续处理.......
elif self.page.wait.eles_loaded("#login-form"):
print('需要登陆/换IP')
# 需要继续处理.......
def run(self):
for i in range(1, 100000):
self.request_body()
if __name__ == '__main__':
detail = Detail()
detail.run()

View File

@ -0,0 +1,57 @@
import re
import json
from spider.baes import Baes
import http.client
import time
class Detail(Baes):
def __init__(self):
self.url = "/offer/643272204627.html"
super().__init__()
def request_body(self):
headers = {
'Referer': 'https://mail.qq.com/',
'cookie': 'x5sec=7b22733b32223a2235376666613964313830393261636362222c226c61707574613b32223a226331366632616261613731343933646339653661353332363564326564343639434b4b7933625147454a4b64385a37372f2f2f2f2f774577397179704b673d3d227d',
'User-Agent': (
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/126.0.0.0 Safari/537.36'
),
}
conn = http.client.HTTPSConnection("detail.1688.com")
try:
conn.request("GET", self.url, headers=headers)
response = conn.getresponse()
# print(response.read().decode('latin-1'))
# exit()
if response.status == 200:
data = response.read().decode("utf-8")
pattern = r'window\.__INIT_DATA\s*=\s*(\{.*?\})\s*</script>'
match = re.search(pattern, data)
json_data = match.group(1)
dict_data = json.loads(json_data)
temp_model = dict_data.get('globalData').get('tempModel')
print(temp_model)
else:
print(f"Request failed with status {response.status}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
conn.close()
def run(self):
for i in range(1, 1000):
self.request_body()
# time.sleep(3)
if __name__ == '__main__':
detail = Detail()
detail.run()