简体   繁体   中英

Scrapy Request GET url, How can I add keyword in url?

I have this url www.example.com. I need to send this url in scrapy Request method,How can I attain that? url_final = https://www.example.com/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=MYSEARCHKEY&_sacat=0

url = 'httpss://www.example.com/'
MYSEARCHKEY = 'MYSEARCHKEY'
yield Request(url_final, callback=self.parse_new)

You can use python library for urlencoding to create final URL.

from urllib.parse import urlencode
params={'_from':'R40',
        '_trksid':'m570.l1313',
        '_nkw':'MYSEARCHKEY',
        '_sacat':0}
base_url=' https://www.example.com/sch/i.html'
final_url= '{}?{}'.format(base_url,urlencode(params))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM