3-1 urllib基本用法

3-1 urllib基本用法

 

C:\Users\Administrator\PycharmProjects\python_data_collection\python_data_collection\urllib_hlg_test.py

from urllib import request

resp = request.urlopen("http://www.baidu.com")
print(resp.read().decode("utf-8"))

 

 

C:\Users\Administrator\PycharmProjects\python_data_collection\python_data_collection\urllib_hlg_test.py

from urllib import request

req = request.Request("http://www.baidu.com")
req.add_header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36")
resp = request.urlopen(req)
print(resp.read().decode("utf-8"))

 

 

 

 

 

 

 

https://www.thsrc.com.tw/ArticleContent/a3b630bb-1066-4352-a1ef-58c7b4e8ef7c

 

from urllib.request import urlopen
from urllib.request import Request
from urllib import parse

req = Request("https://kyfw.12306.cn/otn/leftTicket/init")
postData = parse.urlencode([
    ("leftTicketDTO.train_date","2021-03-18"),
("leftTicketDTO.from_station","SHH"),
("leftTicketDTO.to_station","BZH"),
("purpose_codes","ADULT"),
])

req.add_header("Referrer Policy","strict-origin-when-cross-origin")
req.add_header("User-Agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36")

resp = urlopen(req, data=postData.encode("utf-8"))

print(resp.read().decode("utf-8"))

 

 

 

 

 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值