警告:本教程僅可由於合法用途,由此帶來的一切法律與其他形式責任自負。
selenium無頭瀏覽器–谷歌 - 北邊的大魚 -
import requests
import re
from selenium import webdriver
# 建立乙個引數物件,用來控制chrome以無介面模式開啟
chrome_options = webdriver.chromeoptions(
)chrome_options.add_argument(
'--headless'
)# # 瀏覽器不提供視覺化頁面
chrome_options.add_argument(
'--disable-gpu'
)# 禁用gpu加速,gpu加速可能會導致chrome出現黑屏,且cpu佔用率高達80%以上
chrome_options.add_experimental_option(
'excludeswitches',[
'enable-logging'])
#不列印日誌 否則每次抓取都會列印
driver = webdriver.chrome(options=chrome_options, executable_path=r'***xx'
)#這裡是chromedriver路徑
#建立物件
for i in
range
(1140089847
,1150170000):
#i即為userid
url=
""url=url.
format
(i) driver.get(url)
username = driver.find_elements_by_class_name(
'f-thide')[
1].text #匹配到三個物件,第二個為使用者名稱所在
#if(('u'in username) or('u' in username) or('大學' in username)): #篩選有用資訊
print
(i,end =
" ")
print
(username)
中國大學MOOC 學習筆記(三)
在學習了嵩天老師的 python網路爬蟲與資訊提取課程 之後,我自己嘗試按照老師的步驟做了乙個小demo。url 如下 import requests from bs4 import beautifulsoup 獲得response物件 defgeturltext url r requests.ge...
中國大學MOOC 學習筆記(一)
注 本文僅是個人的學習筆記,內容 於中國大學mooc python網路爬蟲與資訊提取 課程 一 京東商品頁面爬取 import requests url try r requests.get url r.raise for status 檢查訪問資訊的狀態碼,200表示正確 將編碼改為可以顯示的編碼...
我的Python筆記(中國大學MOOC)
使用舉例 cd py 檔案路徑下 pyinstaller i 檔案.ico f 檔案.py 生成的檔案dist中有可執行檔案str str 新字元 陣列形式 str str input str str.lower 分割是split 替換是str.replace 新的,目標 留乙個好的文章 try e...