今天不知道是不是哪里误操作了,在Pycharm的run界面无论运行任何命令都出现 AttributeError: 'NoneType' object has no attribute 'loader',如图1
在运行某些代码时还会出现:SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?,如图2、3
图2 代码:
import requests from lxml import etree from chaojiying import Chaojiying_Client header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 SLBrowser/7.0.0.5211 SLBChan/25"} url = 'https://so.gushiwen.org/user/login.aspx?from=http://so.gushiwen.org/user/collect.aspx' page_text = requests.get(url=url,headers=header).text tree = etree.HTML(page_text) code_img_src = 'https://so.gushiwen.org'+tree.xpath('//*[@id="imgCode"]/@src')[0]#解析验证码图片img中src属性值 img_data = requests.get(url=code_img_src,headers=header).content with open('./爬取验证码.jpg','wb') as fp: fp.write(img_data)#将验证码图片保存到了本地 chaojiying = Chaojiying_Client('hc726568076', '123123', '944745') im = open('//爬取验证码.jpg', 'rb').read() # 读取保存的图片 print(chaojiying.PostPic(im, 1902))
求各位大佬指点