问一下,我这运行会报错,是因为什么,找了半天没找到原因
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