0

I am a beginner of web scripting.

I was following a tutorial on Edureka: A Beginner’s Guide to learn web scraping with python!.

There is a syntax error shown inside the URL of my script:

driver.get('<a href='https://www.jbhifi.com.au/products/lenovo-ideapad-slim-5i-15-6-full-hd-laptop-512gb-intel-i5'>https://www.jbhifi.com.au/collections/computers-tablets/windows-laptops?page=4')   

The invalid syntax seems under com, which is very confusing to me.

I have no idea how to solve it.

4
  • Do you really not see it? You have a string, '<a href='. That's all there is of the string, because you closed the quote. Everything that follows is garbage. The solution, when you have single quotes in a string, is to wrap the string in DOUBLE quotes. "<a href='https...>". Commented Jul 28, 2021 at 5:18
  • What is your relationship to the site you are linking to? Edureka has a history of recent spamming of the Stack Overflow network. Commented Jul 28, 2021 at 5:32
  • Please note, that the Python source example given on that tutorial contains syntax-errors (illegal quoting inside a string): driver.get("<a href="https://www.flipkart.com/laptops/"> ...) (ellipses on the end added by me) Commented Jul 28, 2021 at 5:45
  • @tripleee I searched the web scripting python for beginner on google and Edureka is the top few websites I saw. I didn't know about the spamming thing here. Thanks for telling me that. Commented Jul 28, 2021 at 6:27

2 Answers 2

1

The syntax error is because you are enclosing your string with single quotes, and you also have single quotes inside the string. So Python thinks that everything after '<a href=' is not a string, but it can't interpret that other stuff as Python code, so Python gives up and raises an error.

Normally you would deal with this by enclosing the string with double quotes, or by escaping the single quotes. However, with driver.get, you don't use the <a href="..."> part; you just give it the URL. So you can do this:

driver.get('https://www.jbhifi.com.au/collections/computers-tablets/windows-laptops?page=4')
Sign up to request clarification or add additional context in comments.

Comments

0

You cannot use same type of quotes inside and out within the same string. You can either use single and double quotes together or you can escape it. Modify your script as follows:

driver.get('<a href="https://www.jbhifi.com.au/products/lenovo-ideapad-slim-5i-15-6-full-hd-laptop-512gb-intel-i5">)   

1 Comment

driver.get only takes the URL, so the <a href="..."> HTML syntax should be removed. Check step 4 of the tutorial the OP linked to for an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.