python学习问题记录
2017-08-16 16:13
375 查看
1、from bs4 import BeautifulSoup 报错 ImportError: No module named bs4
引用之前我已经安装了 BeautifulSoup 模块,但还是报错,最终原因是我没有安装BeautifulSoup4,使用命令 pip install BeautifulSoup4,之后就解决了2、从网页抓取的内容不全(还以为网站做了什么限制,不让抓取,因为有的网址使用该方法就挺全的)
url="http://hy.werer.cn/index.php?qb=p&page=2" request = urllib2.Request(url=url,headers=headers) response = urllib2.urlopen(request) html = response.read() html = BeautifulSoup(html)解决办法:
修改 BeautifulSoup的参数
html = BeautifulSoup(html,"html5lib",from_encoding='gb2312')
注意这里的html5lib是个模块,要进行安装和引用的 安装使用 pip install html5lib,然后在头部 import html5lib
3、Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
因为我的mysql.sock在 tmp文件夹下,所以链接项需要设置db = MySQLdb.connect(host='localhost', user='root', passwd='root', db='python', port=3306, charset='utf8', unix_socket='/tmp/mysql.sock',cursorclass = MySQLdb.cursors.DictCursor)
4、只要脚本里面有中文,运行就报错 but no encoding declared
在py文件的第一行加上 #coding=utf-8
相关文章推荐
- Python字符编码问题-学习记录
- 记录学习python时的问题(二)
- 既然决定学习python就开始记录一些问题吧
- Python学习问题记录
- 【Python3.6爬虫学习记录】(七)使用Selenium+ChromeDriver爬取知乎某问题的回答
- Python 学习记录(1)对象命名导致的问题
- python3学习记录——安装pyspider中lxml安装问题
- Python 学习问题记录
- python django学习-问题记录及解决方法
- 学习python过程遇到的问题与记录
- python3学习记录——安装pyspider中lxml安装问题
- 记录学习python时的问题(一)
- 记录Python学习中的几个小问题
- Ubuntu中python环境下import requests错误的解决(学习过程问题记录)
- 学习Python 是遇到的一些问题记录
- django学习记录,动态url,另外发现django的时区问题
- [项目过程中所遇到的各种问题记录]学习篇——对工作以来的学习过的开源项目进行总结—DiscuzNt
- python学习记录
- [项目过程中所遇到的各种问题记录]学习篇——对工作以来的学习过的开源项目进行总结—动软代码生成工具
- Python模块学习 ---- logging 日志记录(一)