原创 requests的一些操作筆記

import requests,json url = 'http://httpbin.org/get' r = requests.get(url) print(r.status_code,r.reason) # 200 ok print

原创 BeautifulSoup中has_attr和attrs使用

from bs4 import BeautifulSoup import requests,lxml r = requests.get('http://www.xiachufang.com/') soup = BeautifulSou

原创 urllib中urlparse使用技巧以及iter_content圖片邊下邊存到硬盤使用

import os,requests from urllib.parse import urlparse # 如果獲取的鏈接地址如下,但是我們只想要問號前面的怎麼處理 url = 'http://i2.chuimg.com/657f

原创 獲取遷木網QS世界大學排名信息

處理網址:http://www.qianmu.org/ranking/1528.htm # 獲取qianmu遷木網QS世界大學排名信息 import requests from lxml import etree import re

原创 response.replace(body=response.text.replace(‘\xa0‘,‘‘)),scrapy抓取網頁含\r \t \n \xa0時,修改response方法

xpath抓取數據值有\r\n\t時去掉的方法:https://blog.csdn.net/z564359805/article/details/101597953 抓取網頁含\r \t \n時,用normalize-space出現特殊符

原创 XPATH語法contains包含和positon位置及價格大於多少的使用

# 選取class屬性包含ing的href鏈接地址 html.xpath("//div/p[2][contains(@class,'ing')]/a/@href") # 選取價格大於20元書的價格值 html.xpath("//book

原创 Python3中argparse基本用法

argparse 是python自帶的命令行參數解析包,可以用來方便地讀取命令行參數。 #!/usr/bin/env python # coding=utf-8 import argparse def main(): # d

原创 xpath抓取數據值有\r\n\t時,去掉的方法normalize-space()

主要使用:normalize-space() 之前寫法:response.xpath('//*[@id="to"]/tbody/tr/td[3]/a/text()') 修改後:response.xpath('normalize-space

原创 selenium獲取結果轉爲json格式

from selenium import webdriver from bs4 import BeautifulSoup option = ChromeOptions() option.add_experimental_option

原创 pycharm上傳GitHub時報錯:push failed: fatal: unable to access 'https://github.com/***port 443: Timed out

系統證書問題,系統判斷這個行爲會造成不良影響,所以進行了阻止,只需要設置跳過SSL證書驗證即可。 1.在當前項目根目錄中打開Git(右鍵選擇 Git Bash Here) 2.運行: git config --global http.s

原创 github桌面版不能訪問fatal: unable to access,ping不通github.com解決辦法(已成功)

打開 hosts文件,地址:C:\Windows\System32\drivers\etc  在文件末尾添加如下內容,並保存: 192.30.255.112  github.com git 185.31.16.184 github.gl

原创 獲取大麥網孟鶴堂演出數據並播報和在右下角彈窗提示

  #!/usr/bin/env python # coding=utf-8#!/usr/bin/env python # coding=utf-8 # 獲取大麥網孟鶴堂演出數據並播報和在右下角彈窗提示 import requests

原创 Django自學筆記之全文檢索

1.依次安裝以下包:  pip install django-haystack pip install whoosh pip install jieba 2.修改settings.py文件:  添加應用  INSTALLED_APPS

原创 Django自學筆記之admin中設置App名稱爲中文

如圖所示,這個便是Django中admin應用默認顯示的英文名稱: 然後找到對應應用下的“apps.py”以及初始化文件“__init__.py”: 接着在init中導入AppConfig以及os模塊: # df_goods/__i

原创 python3中datetime模塊當前時間多加一天、一小時、一分鐘

現在的時間減去2分鐘31秒後得出的時間:  >>>(datetime.datetime.now() - datetime.timedelta(minutes=2,seconds=31)).strftime("%H:%M:%S") 15: