不需要处理cookies——爬拉勾网职位信息
import requests
urls ='https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput='
url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false'
s = requests.Session()
s.get(urls, headers=header, timeout=3)
cookie = s.cookies
response = s.post(url, data=payload, headers=header, cookies=cookie, timeout=5).text
爬取京东商品信息
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
bro=webdriver.Chrome(executable_path='./chromedriver.exe')
bro.implicitly_wait(10)
def get_goods_info(bro):
goods = bro.find_elements_by_css_selector('.gl-item')
for good in goods:
try:
price = good.find_element_by_css_selector('.p-price i').text
name = good.find_element_by_css_selector('.p-name em').text
url = good.find_element_by_css_selector('.p-img a').get_attribute('href')
commits = good.find_element_by_css_selector('.p-commit strong>a').text
photo_url = good.find_element_by_css_selector('.p-img').get_attribute('src')
except Exception as e:
continue
next_button = bro.find_element_by_partial_link_text('下一页')
time.sleep(1)
next_button.click()
get_goods_info(bro)
try:
bro.get('https://www.jd.com/')
input_k=bro.find_element_by_id('key')
input_k.send_keys('奶牛')
input_k.send_keys(Keys.ENTER)
get_goods_info(bro)
except Exception as e:
print(e)
finally:
bro.close()
自动登录12306
from selenium import webdriver
import time
from PIL import Image
from chaojiying import Chaojiying_Client
from selenium.webdriver import ActionChains
bro=webdriver.Chrome(executable_path='./chromedriver.exe')
bro.implicitly_wait(10)
try:
bro.get('https://kyfw.12306.cn/otn/resources/login.html')
bro.maximize_window()
button_z=bro.find_element_by_css_selector('.login-hd-account a')
button_z.click()
time.sleep(2)
bro.save_screenshot('./main.png')
img_t=bro.find_element_by_id('J-loginImg')
print(img_t.size)
print(img_t.location)
size=img_t.size
location=img_t.location
img_tu = (int(location['x']), int(location['y']), int(location['x'] + size['width']), int(location['y'] + size['height']))
img = Image.open('./main.png')
fram = img.crop(img_tu)
fram.save('code.png')
chaojiying = Chaojiying_Client('306334678', 'lqz12345', '903641')
im = open('code.png', 'rb').read()
res=chaojiying.PostPic(im, 9004)
print(res)
result=res['pic_str']
all_list = []
if '|' in result:
list_1 = result.split('|')
count_1 = len(list_1)
for i in range(count_1):
xy_list = []
x = int(list_1[i].split(',')[0])
y = int(list_1[i].split(',')[1])
xy_list.append(x)
xy_list.append(y)
all_list.append(xy_list)
else:
x = int(result.split(',')[0])
y = int(result.split(',')[1])
xy_list = []
xy_list.append(x)
xy_list.append(y)
all_list.append(xy_list)
print(all_list)
for a in all_list:
x = a[0]
y = a[1]
ActionChains(bro).move_to_element_with_offset(img_t, x, y).click().perform()
time.sleep(1)
username=bro.find_element_by_id('J-userName')
username.send_keys('306334678')
password=bro.find_element_by_id('J-password')
password.send_keys('lqz12345')
time.sleep(3)
submit_login=bro.find_element_by_id('J-login')
submit_login.click()
time.sleep(3)
print(bro.get_cookies())
time.sleep(10)
bro.get('https://www.12306.cn/index/')
time.sleep(5)
except Exception as e:
print(e)
finally:
bro.close()
session自动cookies——模拟登陆某网站
import requests
session=requests.session()
data = {
'username': '616564099@qq.com',
'password': 'lqz123',
'captcha': 'zdu4',
'remember': 1,
'ref': 'http://www.aa7a.cn/user.php?act=logout',
'act': 'act_login',
}
rest = session.post('http://www.aa7a.cn/user.php',data=data)
cookie=rest.cookies
rest1=session.get('http://www.aa7a.cn/index.php')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现