[python爬蟲]收納一些常見問題

數據獲取

1>一個標籤中有多行數據, 如何分行獲取
我遇到的情況是這樣的:
紅線是目標數據
源碼是:

<p>
	杭州 餘杭區 倉前
	<em class="vline"></em>
	1-3年
	<em class="vline"></em>
	本科
</p>

解決方法

# selenium獲取這個p標籤的源碼,然後split成list
info_ls = chrome.find_element_by_xpath('//div[@class="job-banner"]//p').get_attribute('innerHTML').split('<em class="vline"></em>')
item['City'] = info_ls[0]	# 城市
item['eduLevel'] = info_ls[1]	# 學歷
item['workingExp'] = info_ls[2]		# 工作經驗

Pyspider

1>安裝pyspider過程出錯:ERROR: Command errored out with exit status 10: python setup.py egg_info Check…
https://blog.csdn.net/weixin_43810415/article/details/99694315

2>pyspider all運行出錯:①SyntaxError: invalid syntax,② - Deprecated option ‘domaincontroller’: use 'http_au
https://blog.csdn.net/u012424313/article/details/89511520

3>運行時出現: ValueError: Invalid configuration
解決方法: pip install wsgidav==2.4.1

4>運行時卡在result_worker starting…
錯誤如下:

(venv1) D:\Fire\PycharmProject\pyspider\test1&gt;pyspider
c:\users\xxx\pycharmprojects\untitled1\venv1\lib\site-packages\pyspider\libs\utils.py:196: FutureWarning: timeout is not supported on you
r platform.
  warnings.warn(&quot;timeout is not supported on your platform.&quot;, FutureWarning)
[W 191028 21:30:05 run:413] phantomjs not found, continue running without it.
[I 191028 21:30:07 result_worker:49] result_worker starting...

解決方法:
下載phantomjs, 然後將phantomjs.exe拖到python根目錄, 重新運行即可
如果還是不行,請參考:https://blog.csdn.net/qq_35167821/article/details/89162394

5. 在實際的調試中發現pyspider的Web預覽界面只有一點非常小
這篇文章中的第3個:
https://www.jianshu.com/p/7bff6fd4dc1b


數據儲存

1>MongoDB讓數據具有過期時間
主要使用pymongo庫中的createIndex()方法, 其中有個expireAfterSeconds的參數, 作用是指定一個以秒爲單位的數值,可以用來創建一個具有過期時間的索引, 這樣之後寫入的集合就可以擁有過期時間
詳情參考: https://www.runoob.com/mongodb/mongodb-indexing.html
注:指定的索引寫入時必須爲datetime格式, 否則不會自動刪除


其他問題

1>解決windows下 cd 無法切換盤符目錄
https://blog.csdn.net/kakuma_chen/article/details/71173243

2>關於解決’\u’開頭的字符串轉中文的方法
https://www.cnblogs.com/hahaxzy9500/p/7685955.html

3>修改jupyter notebook啓動的虛擬環境
合併查看一下兩篇文章:
https://blog.csdn.net/hao5335156/article/details/81165727
https://blog.csdn.net/weixin_41813895/article/details/84750990

4.python爬蟲 隨機UA庫
https://blog.csdn.net/qq_18525247/article/details/81355397

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章