alicelo
alicelo

Reputation: 1

Web scripting invalid syntax in URL

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.

Upvotes: 0

Views: 979

Answers (2)

Coder94
Coder94

Reputation: 1035

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">)   

Upvotes: 0

Jack Taylor
Jack Taylor

Reputation: 6217

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')

Upvotes: 1

Related Questions