提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
记录1:Xpath爬取tbody为空
问题描述
XPATH 中爬取空列表(tbody)
原因分析:
原因是因为浏览器会对html文本进行一定的规范化
解决方案:
去掉xpath中的tbody即可
记录2:yagmail发送邮件报错SMTPAuthenticationError
问题描述
def sendmail(text):
yag = yagmail.SMTP(user='111111111@qq.com', password='1123123', host='smtp.qq.com')
# sending the email
yag.send(to='2222222@qq.com', subject='a', contents=text)
报错如下
Traceback (most recent call last):
File "D:/Python/Project/dk/dk2.py", line 60, in <module>
sendmail("a")
File "D:/Python/Project/dk/dk2.py", line 58, in sendmail
yag.send(to='111111111@qq.com', subject='a', contents=text)
File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\yagmail\sender.py", line 156, in send
self.login()
File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\yagmail\sender.py", line 210, in login
self._login(self.credentials)
File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\yagmail\sender.py", line 229, in _login
self.smtp.login(self.user, password)
File "C:\Program Files\Python36\lib\smtplib.py", line 730, in login
raise last_exception
File "C:\Program Files\Python36\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "C:\Program Files\Python36\lib\smtplib.py", line 642, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'Login Fail. Please enter your authorization code to login. More information in http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256')
原因分析:
yagmail 所需的password 并非真实邮箱密码,而是邮箱的授权码
解决方案:
记录3:datetime一些使用上的报错
问题描述
试图用datetime获取当前时间信息,并只显示年月日:
now_date = datetime.now()
print(now_date[0:10])
报错如下
Traceback (most recent call last):
File "D:/Python/Project/dk/dk2.py", line 78, in <module>
now_date = datetime.now()
AttributeError: module 'datetime' has no attribute 'now'
原因分析:
未知
解决方案:
将代码改为:
now_date = datetime.datetime.now()
print(now_date[0:10])
继续报错:
Traceback (most recent call last):
File "D:/Python/Project/dk/dk2.py", line 79, in <module>
print(now_date[0:10])
TypeError: 'datetime.datetime' object is not subscriptable
再将datetime对象修改为str:
now_date = datetime.datetime.now().strftime('%Y-%m-%d')
print(now_date[0:10])