写一个scrpy蜘蛛,出错了

时间:2018-04-24 02:50:12

标签: python scrapy

这是我的代码,我不知道如何修复它:

  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\shang\404.py", line 122
    for 'post-header' in response.css('header.post-header'):
       ^
SyntaxError: can't assign to literal

1 个答案:

答案 0 :(得分:0)

您的代码正在尝试将函数调用的结果(response.css())分配给字符串文字('post-header'),这没有任何意义。

您需要改为分配变量:

for x in response.css('header.post-header'):
    # do something with x

请注意,变量名称x只是一个任意标签,因此您还可以使用更易读的名称,例如post_header

for post_header in response.css('header.post-header'):
    # do something with post_header