内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

爬蟲常用筆記總結(jié)-創(chuàng)新互聯(lián)

方法

創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比長(zhǎng)治網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式長(zhǎng)治網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋長(zhǎng)治地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。
import requests
from bs4 import BeautifulSoup
from fake_useragent import FakeUserAgent

hd = {'User-Agent': FakeUserAgent().random}
r = requests.get('https://www.meishij.net/fenlei/zaocan/', headers=hd)
# r.status_code   # 查看狀態(tài)
# r.encoding  # 編碼 ISO-8859-1
r.encoding = 'UTF-8'  # 轉(zhuǎn)換編碼格式
soup = BeautifulSoup(r.text, 'html.parser')  # r.content

"""

"""
# 指定標(biāo)簽
alst = soup.find_all('table')
for i in alst:
    print(i.a.get('title'), i.span.string, '\t', i.p.string)

# 指定樣式 class_
info_all = soup.find_all('div', class_='list_s2_item')
for i in info_all:
    info1 = i.find('a', class_='list_s2_item_info').strong.string
    info2 = i.find('a', class_='list_s2_item_info').span.string

# 指定元素
address = soup.select(
    'body >div.comm-content-box.clearfloat >div >div.comm-content-left.clearfloat >div >div.xq_toggle >div:nth-child(2) >table:nth-child(1) >tbody >tr:nth-child(2) >td:nth-child(2)')
print(address[0].string)

"""
獲取內(nèi)容語法
data.get_text()   # 獲取data中文本內(nèi)容
p.string  #

張三

a.get('title') # title='張三' """

借用網(wǎng)站功能查IP地址:

import requests
from bs4 import BeautifulSoup
from fake_useragent import FakeUserAgent


def get_address_by_ip(ip):
    hd = {'User-Agent': FakeUserAgent().random}
    url = 'https://ip.hao86.com/' + ip + '/'
    r = requests.get(url, headers=hd)
    r.encoding = 'UTF-8'
    soup = BeautifulSoup(r.text, 'html.parser')
    address = soup.select(
        'body >div.comm-content-box.clearfloat >div >div.comm-content-left.clearfloat >div >div.xq_toggle >div:nth-child(2) >table:nth-child(1) >tbody >tr:nth-child(2) >td:nth-child(2)')
    return address[0].string


IP = input('輸入你要查詢的IP:')  # 221.218.142.209
address = get_address_by_ip(IP)
print(address)

保存圖片:

import requests
import os

'''
爬取指定url圖片
可能出現(xiàn)的問題:圖片地址不合法,缺少http
http://upload.techweb.com.cn/s/310/2018/0410/1523330175838.jpg
'''
url4 = 'http://img.netbian.com/file/2022/1127/small1208244iXg61669522104.jpg'

theUrl = url4  # 指定要爬取的url

# 爬取到的圖片存在電腦那個(gè)磁盤位置
root = "d://pythonZoneHH//pic2HH//"

path = root + theUrl.split("/")[-1]  # 這句話可以保證原來圖片叫什么名字,爬下來時(shí)候還叫什么名字
print(path)
try:
    if not os.path.exists(root):  # 判斷磁盤制定文件夾是否存在,
        os.makedirs(root)  # 如果不存在就創(chuàng)建文件夾

    r = requests.get(theUrl)
    print("文件大小", len(r.content) / 1024, "kb")
    with open(path, "wb") as f:
        print("正在保存文件...")
        f.write(r.content)  # 向文件中寫入二進(jìn)制內(nèi)容
        print("文件保存成功")
except Exception as e:
    print("爬取失敗", e)

頁(yè)面中不存在的數(shù)據(jù)爬?。?/p>

右鍵檢查,從網(wǎng)絡(luò)的請(qǐng)求中的找到對(duì)應(yīng)數(shù)據(jù),在標(biāo)頭中復(fù)制出URL

import json

from bs4 import BeautifulSoup
import requests
from fake_useragent import FakeUserAgent

re_url = 'https://www.thecfa.cn/index.html'
url = 'https://www.thecfa.cn/nvzgjd/dataApi/text/v1?contId=30235&next=-1'
hd = {'User-Agent': FakeUserAgent().random, 'Referer': re_url}  # Referer:re_url 設(shè)置引用頁(yè)
r = requests.get(url, headers=hd)
r.encoding = 'UTF-8'
# r.text 獲取到的是一個(gè)字符串  {"text":" 國(guó)際足聯(lián)排名..."}  類型:dic = json.loads(r.text)  # 字符串轉(zhuǎn)json數(shù)據(jù)  用 json.loads(內(nèi)容)
html_doc = dic.get('text')  # 通過 .get('鍵')  取出值即可
soup = BeautifulSoup(html_doc, 'html.parser')
info_all = soup.find_all('li')
for i in info_all:
    # print(i, '....')
    date = i.find('div', class_='date').get_text()
    img_url = i.find_all('div', class_='country')[0].p.img.get('src')
    score = i.find('div', class_='score').get_text()
    img_url2 = i.find_all('div', class_='country')[1].p.img.get('src')
    print(date, '\t', img_url, '\n', score, '\t', img_url2)

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

網(wǎng)頁(yè)標(biāo)題:爬蟲常用筆記總結(jié)-創(chuàng)新互聯(lián)
鏈接分享:http://www.rwnh.cn/article42/coisec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站排名、外貿(mào)建站、微信小程序定制網(wǎng)站、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)
望奎县| 乌拉特前旗| 军事| 滕州市| 波密县| 左云县| 武胜县| 陆川县| 蓬安县| 清水县| 盐津县| 元谋县| 宁夏| 洛阳市| 黄龙县| 长岭县| 深水埗区| 贞丰县| 上蔡县| 双柏县| 始兴县| 长海县| 集安市| 天长市| 南部县| 自贡市| 江津市| 青田县| 万全县| 通河县| 咸阳市| 马尔康县| 英德市| 北海市| 乌兰察布市| 贵州省| 高阳县| 金川县| 高邑县| 康平县| 四会市|