0

I am using Python 3.6

This is my url address.

http://www.bobaedream.co.kr/mycar/popup/mycarChart_B.php?car_number=35두8475&tbl=cyber&cno=651451

I would like to extract "35두8475" and "651451". How can I do this?

Below is my code but it keeps returning an error message, 'function' object has no attribute 'parse_qs' Please give me some advice.

Thanks.

from urllib.parse import urlparse
url = 'http://www.bobaedream.co.kr/mycar/popup/mycarChart_B.php?car_number=35두8475&tbl=cyber&cno=651451'
parsed = urlparse(url)
print(urlparse.parse_qs(parsed)['no'])
신종원
  • 195
  • 1
  • 11

1 Answers1

2
import urlparse
url = 'http://www.bobaedream.co.kr/mycar/popup/mycarChart_B.php?car_number=35두8475&tbl=cyber&cno=651451'
parsed = urlparse.urlparse(url)
print urlparse.parse_qs(parsed.query)['car_number']

Check Retrieving parameters from a URL

Community
  • 1
  • 1
alphiii
  • 1,597
  • 3
  • 21
  • 27
  • I am using python 3.6. When I tried with your code, it keeps returning an error message, "No module named 'urlparse'" even though I changed my code like below: – 신종원 Dec 29 '16 at 09:04
  • from urllib.parse import urlparse url = 'http://www.bobaedream.co.kr/mycar/popup/mycarChart_B.php?car_number=35두8475&tbl=cyber&cno=651451' parsed = urlparse(url) print(urlparse.parse_qs(parsed)['no']) – 신종원 Dec 29 '16 at 09:05
  • I figured out!! Thanks!! – 신종원 Dec 29 '16 at 09:27
  • Yes urllib on python3 is a bit different.This process to get query parameters is quite easy since it is standard GET request. – alphiii Dec 29 '16 at 09:39