个人兴趣,开始学习python,主要是爬虫相关编程,当然只是随笔,记录学习过程中遇到的不解,问题和解决方法,如果疑问欢迎留言,共同学习,共同记录(持续更新)
#1.20200421-print输入respone不能换行的问题
import urllib.parse
import urllib.request
data = bytes(urllib.parse.urlencode({'word':'hello'}),encoding='utf8')
respone = urllib.request.urlopen('http://httpbin.org/post', data=data)
#print(respone.read())
print(respone.read().decode('utf-8'))//只是需要在这里添加解码并可以换行输出
#2.20200422-爬取猫眼电影排行版需要User-Agent
import requests
from requests.exceptions import RequestException
import re
def get_one_page(url):
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.text
return None
except RequestException:
return None
url= 'http://maoyan.com/board/4'
html = get_one_page(url)
print(html)
#2.20200520-Python使用GUI后运行命令行bat或者powershell 会弹出窗口的问题
转https://www.cnblogs.com/gaigaige/p/7881130.html
import subprocess
st=subprocess.STARTUPINFO
st.dwFlags=subprocess.STARTF_USESHOWWINDOW
st.wShowWindow=subprocess.SW_HIDE
subprocess.Popen("adb devices", stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE,startupinfo=st)