Issue
Here is my code , I don't know how to fix it:
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
Solution
Your code is trying to assign the result of a function call (response.css()
) to a string literal ('post-header'
), which makes no sense.
You need to assign to a variable instead:
for x in response.css('header.post-header'):
# do something with x
Note that the variable name x
is just an arbitrary label, so you could also use a more readable name like post_header
:
for post_header in response.css('header.post-header'):
# do something with post_header
Answered By - Richard Inglis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.