

Python,速成心法
敲代码,查资料,问Ai
练习,探索,总结,优化

★★★★★博文创作不易,使用代码的过程中,如有疑问的地方,欢迎大家指正留言交流。喜欢的老铁可以多多点赞+收藏分享+置顶,小红牛在此表示感谢。★★★★★
---------★爬虫系列教程★----------
Python爬虫教程34:如何在访问网址失败后,间隔(2秒、3秒)进行重试
Python爬虫教程33:you-get爬虫利器,一行代码实现,视频+音频+图片的下载
Python爬虫教程32:东财上面获取,股票行业板块的名称+代码数据(json解析)
Python爬虫教程31:requests手动指定网页编码+自动检测的方法
Python爬虫教程30:Selenium网页元素,定位的8种方法!
Python爬虫教程29:使用fake_useragent模块,随机生成User Agent字符串
Python教程69:解密JavaScript中,常见的加密方法
Selenium教程05:使用webdriver-manager自动下载浏览器驱动,再也不用担心driver版本的问题了
Python爬虫教程28:聊聊反爬爬虫经常遇到的问题及解决方法
Python爬虫教程27:秀啊!用Pandas 也能爬虫??
Python爬虫教程26:selenium使用stealth.min.js文件,隐藏浏览器指纹特征
Python爬虫教程20:ip138.com手机号码,归属地查询
Python爬虫教程12:使用urlretrieve下载王者荣耀英雄皮肤
Python爬虫教程10:使用json解析股票数据,并画上证指数K线图
Python爬虫教程09:使用Json解析艺恩娱数网票房数据可视化
Python爬虫教程08:使用json解析中国气象局的天气数据
Python爬虫教程06:使用xpath和正则表达式采集豆瓣250数据
import requestsheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'}resp = requests.get('https://example.com', headers=headers)
from fake_useragent import UserAgentua = UserAgent()headers = {'User-Agent': ua.random}
proxies = {'http': 'http://127.0.0.1:8080','https': 'https://127.0.0.1:8080'}resp = requests.get('https://example.com', proxies=proxies)
import requestsfrom bs4 import BeautifulSoupdef get_free_proxies():url = 'https://free-proxy-list.net/'soup = BeautifulSoup(requests.get(url).text, 'html.parser')proxies = []for row in soup.select('table.table tbody tr'):cells = row.find_all('td')if cells[6].text == 'yes': # HTTPS 支持proxy = f"{cells[4].text.lower()}://{cells[0].text}:{cells[1].text}"proxies.append(proxy)return proxies
import timeimport randomfor url in url_list:resp = requests.get(url, headers=headers)time.sleep(random.uniform(1, 3)) # 随机睡眠1~3秒
headers = {'User-Agent': '...','Accept': 'text/html,application/xhtml+xml,...','Accept-Language': 'zh-CN,zh;q=0.9','Referer': 'https://www.google.com/','Cookie': 'your_cookie_value'}
session = requests.Session()session.headers.update(headers)resp = session.get('https://example.com/login')# 登录后 session 会自动携带返回的 Cookie

# 直接请求数据接口api_url = 'https://example.com/api/getData?param=value'resp = requests.get(api_url, headers=headers)data = resp.json()
from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsoptions = Options()options.add_argument('--headless') # 无头模式options.add_argument('--disable-blink-features=AutomationControlled')driver = webdriver.Chrome(options=options)driver.get('https://example.com')content = driver.page_sourcedriver.quit()
from playwright.sync_api import sync_playwrightwith sync_playwright() as p:browser = p.chromium.launch(headless=True)page = browser.new_page()page.goto('https://example.com')content = page.content()browser.close()
# 超级鹰示例(伪代码)from chaojiying import Chaojiying_Clientchaojiying = Chaojiying_Client('username', 'password', 'soft_id')im = open('captcha.png', 'rb').read()result = chaojiying.PostPic(im, 1902) # 1902 为验证码类型code = result['pic_str']
注意事项
完毕!!感谢您的收看
------★★历史博文集合★★------
