python网页请求_python用post请求网页
# -*-coding:utf-8-*-
from bs4 import BeautifulSoup
import requests, time
url = 'https://knewone.com/discover?page='
def get_page(url, data=None): # 獲取頁面
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text, 'html.parser')
imgs = soup.select('a.cover-inner > img')
titles = soup.select('section.content > h4 >a')
links = soup.select('section.content > h4 > a')
# 數據打印
if data is None:
for img, title, link in zip(imgs, titles, links):
data = {
'img': img.get('src'),
'title': title.get('title'),
'link': link.get('href')
}
print data
def get_more_pages(start, end):
for one in range(start, end):
get_page(url + str(one))
time.sleep(2) # 獲取鏈接
get_more_pages(1, 10) # 調用函數
總結
以上是生活随笔為你收集整理的python网页请求_python用post请求网页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python命名空间特性_Python命
- 下一篇: websocket python爬虫_p