15972156903 发表于 2020-11-27 16:48:50

用pycharm爬虫,写完代码运行发现parsel模块不能调用?

用pycharm爬虫,写完代码运行发现parsel模块不能调用(TypeError: 'module' object is not callable)?用pip安装了几次,都是成功,用terminal安装,提示:



Requirement already satisfied: parsel in ./venv/lib/python3.8/site-packages (1.6.0)
Requirement already satisfied: six>=1.6.0 in ./venv/lib/python3.8/site-packages (from parsel) (1.15.0)
Requirement already satisfied: lxml in ./venv/lib/python3.8/site-packages (from parsel) (4.6.1)
Requirement already satisfied: cssselect>=0.9 in ./venv/lib/python3.8/site-packages (from parsel) (1.1.0)
Requirement already satisfied: w3lib>=1.19.0 in ./venv/lib/python3.8/site-packages (from parsel) (1.22.0)



import requests
import parsel

# 1.确定url地址
url = "https://nba.hupu.com/stats/players"

# 2.发送网络请求 requests(js\html\css)
response = requests.get(url=url)
html_data = response.text
#print(html_data)

# 3.数据解析(筛选数据)
# 3.1 转换数据类型
selector = parsel.selector(html_data)
trs = selector.xpath("//tbody/tr")
for tr in trs:
    rank = tr.xpath("./td/text()").get()#排名
    player = tr.xpath("./td/a/text()").get()# 球员
    team = tr.xpath("./td/a/text()").get()# 球队
    score = tr.xpath("./td/text()").get()# 得分
    hit_shot = tr.xpath("./td/text()").get()# 命中_出手
    hit_rate = tr.xpath("./td/text()").get()# 命中率
    hit_three = tr.xpath("./td/text()").get()# 命中_三分
    three_rate = tr.xpath("./td/text()").get()# 三分命中率
    hit_penalty = tr.xpath("./td/text()").get()# 命中_罚球
    penalty_rate = tr.xpath("./td/text()").get()# 罚球命中率
    session = tr.xpath("./td/text()").get()# 场次
    playing_time = tr.xpath("./td/text()").get()# 上场时间
    print(rank,player,team,score,hit_shot,hit_rate,hit_three,three_rate,hit_penalty,
          penalty_rate,session,playing_time)



YunGuo 发表于 2020-11-28 15:47:59

selector = parsel.selector(html_data)
改成
selector = parsel.Selector(html_data)
Selector的S是大写

15972156903 发表于 2020-11-28 16:26:26

YunGuo 发表于 2020-11-28 15:47
改成

Selector的S是大写

感谢。自己太粗心了。。
页: [1]
查看完整版本: 用pycharm爬虫,写完代码运行发现parsel模块不能调用?