用requests 向 https://www.zhihu.com/explore 网站获取网页 我的答案: import requests head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36", "Cookie":"BIDUPSID=AC8515D2346E4DD0DD2792900E8BAC9D; PSTM=1577773735; BAIDUID=AC8515D2346E4DD0930FDC77A5D3D2D7:FG=1; H_PS_PSSID=1464_33048_33059_31254_33098_33101_32961_31709; BD_UPN=12314753; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; delPer=0; BD_CK_SAM=1; PSINO=5; COOKIE_SESSION=416_0_7_3_20_2_0_1_6_2_53_0_2243883_0_55_0_1606101879_0_1606101824%7C9%230_0_1606101824%7C1; BD_HOME=1"} res=requests.get("https://www.zhihu.com/explore",headers=head) print(res.status_code) print(res.text)
用requests 向 https://www.zhihu.com/explore 网站获取网页,并写入工程目录下的web.html文件中 我的答案: import requests head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36", "Cookie":"BIDUPSID=AC8515D2346E4DD0DD2792900E8BAC9D; PSTM=1577773735; BAIDUID=AC8515D2346E4DD0930FDC77A5D3D2D7:FG=1; H_PS_PSSID=1464_33048_33059_31254_33098_33101_32961_31709; BD_UPN=12314753; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; delPer=0; BD_CK_SAM=1; PSINO=5; COOKIE_SESSION=416_0_7_3_20_2_0_1_6_2_53_0_2243883_0_55_0_1606101879_0_1606101824%7C9%230_0_1606101824%7C1; BD_HOME=1"} res=requests.get("https://www.zhihu.com/explore",headers=head) print(res.status_code) print(res.text) date=open("D:\\Project\\web.html","a+",encoding="utf-8") date.write(res.text)
使用 BeautifulSoup 在https://cn.bing.com/网站搜索python,并获取它的搜索列表。
我的答案:import requests
from urllib import parse
from bs4 import BeautifulSoup
head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36",
"Cookie":"BIDUPSID=AC8515D2346E4DD0DD2792900E8BAC9D; PSTM=1577773735; BAIDUID=AC8515D2346E4DD0930FDC77A5D3D2D7:FG=1; H_PS_PSSID=1464_33048_33059_31254_33098_33101_32961_31709; BD_UPN=12314753; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; delPer=0; BD_CK_SAM=1; PSINO=5; COOKIE_SESSION=416_0_7_3_20_2_0_1_6_2_53_0_2243883_0_55_0_1606101879_0_1606101824%7C9%230_0_1606101824%7C1; BD_HOME=1"}
res=requests.get("https://cn.bing.com/search?q=python",headers=head)
soup=BeautifulSoup(res.text,"html.parser")
t=soup.find_all(class_="b_algo")
for i in t:
print(t)