leslie_。 2023-02-27 17:11 采纳率: 0%
浏览 45

关于#python#的问题:找了半天没找到原因

问一下,我这运行会报错,是因为什么,找了半天没找到原因

from lxml import etree
import requests
html = requests.get("https://www.peterx.cn/").content.decode()
hl = etree.HTML(html)
for i in range(30):
    txt = hl.xpath(f'//*[@id="content"]/div[18]/div[{i}]//text()')
    url = hl.xpath(f'//*[@id="content"]/div[18]/div[{i}]//@href')
    a = list(set(txt))
    if a:
        out = [x.strip() for x in a if x.strip() !='']
    if url:
        out.append(*url)
        print(out)
#报错提示
 Traceback (most recent call last):
  File "/Users/leslie/Desktop/b/10_代码演练/xx_20爬虫lx.py", line 17, in <module>
    out.append(*url)
NameError: name 'out' is not defined. Did you mean: 'oct'?
Process finished with exit code 1
  • 写回答

5条回答 默认 最新

  • cjh4312 2023-02-27 17:17
    关注
    评论

报告相同问题?

问题事件

  • 修改了问题 2月27日
  • 修改了问题 2月27日
  • 修改了问题 2月27日
  • 修改了问题 2月27日
  • 展开全部

悬赏问题

  • ¥15 提问一个关于vscode相关的环境配置问题,就是输入中文但是显示不出来,代码在idea可以显示中文,但在vscode不行,不知道怎么配置环境
  • ¥15 netcore使用PuppeteerSharp截图
  • ¥20 这张图页脚具体代码该怎么写?
  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
  • ¥15 数字信号处理考试111
  • ¥15 allegro17.2生成bom表是空白的
  • ¥15 请问一下怎么打通CAN通讯
  • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
  • ¥35 navicat将excel中的数据导入mysql出错