中文乱码
img_name = img_name.encode('iso-8859-1').decode('gbk')
response = requests.get(url=url, headers=headers)
response.encoding = 'utf-8'
response.text 改成 response.content
爬虫
- 解决python爬虫
requests.exceptions.SSLError: HTTPSConnectionPool(host='XXX', port=443)
问题
- 安装
cryptography
、pyOpenSSL
、certifi
三个模块即可
pip install cryptography
pip install pyOpenSSL
pip install certifi
- requests库提示警告:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate ver
- 加入如下代码即可
requests.packages.urllib3.disable_warnings()
- 提取html文件报错
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 4 and head
原因在于html标签未加 / 所有的标签最好都用 / 来结束
TypeError: can only concatenate str (not “list”) to str
(列表和字符串的报错解决方法)
str(title)
- 警告
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service("chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get('https://www.baidu.com/')
driver.quit()
- 标签定位不到
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
bro.find_element(By.XPATH,''
- l类型错误 :
TypeError: ‘ItemMeta‘ object does not support item assignment
item = MeinvproItem()
- scrapy框架写入数据库中存储数据部分代码报错
redis.exceptions.DataError: Invalid input of type: 'dict'. Convert to a byte, string or number first.
jupyter
pip install autopep8
pip install jupyter_contrib_nbextensions -i https://pypi.mirrors.ustc.edu.cn/simple
jupyter contrib nbextension install --user
-------------------------------------------------------------------------------------------------------------------
pip install --user jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user