python 爬虫--天眼查获取内链

import requests
from bs4 import BeautifulSoup
from urllib.parse import quote
key='小米'
url='https://www.tianyancha.com/search?key='+quote(key)
headers={'Cookie': 'aliyungf_tc=92b2b0458ebd5e6b8a8d6adf6862a467030c2ec053818a06fecbefb9c5385117; acw_tc=781bad3a16187345689252945e0d4982d749d9f038dd59ce0e7e3fc8be0487; csrfToken=sbx4nshjEY2FocaXN6EPOYHQ; jsid=https%3A%2F%2Fwww.tianyancha.com%2F%3Fjsid%3DSEM-BAIDU-PZ-SY-2021112-JRGW; ssuid=4822214492; sajssdk_2015_cross_new_user=1; bannerFlag=true; TYCID=32041ca0a02011eb852eff54a8c8391d; undefined=32041ca0a02011eb852eff54a8c8391d; bdHomeCount=0; Hm_lvt_e92c8d65d92d534b0fc290df538b4758=1618734571; _ga=GA1.2.2091989204.1618734572; _gid=GA1.2.1612675400.1618734572; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22237292064%22%2C%22first_id%22%3A%22178e41959a1152-07c36927d26cd6-7d667961-1024000-178e41959a2881%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E5%A4%A9%E7%9C%BC%E6%9F%A5%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2Fother.php%22%7D%2C%22%24device_id%22%3A%22178e41959a1152-07c36927d26cd6-7d667961-1024000-178e41959a2881%22%7D; tyc-user-info={%22claimEditPoint%22:%220%22%2C%22explainPoint%22:%220%22%2C%22vipToMonth%22:%22false%22%2C%22personalClaimType%22:%22none%22%2C%22integrity%22:%2220%25%22%2C%22state%22:%220%22%2C%22score%22:%220%22%2C%22anonymityLogo%22:%22https://static.tianyancha.com/design/anonymity/anonymity2.png%22%2C%22announcementPoint%22:%220%22%2C%22messageShowRedPoint%22:%220%22%2C%22vipManager%22:%220%22%2C%22monitorUnreadCount%22:%220%22%2C%22discussCommendCount%22:%220%22%2C%22onum%22:%220%22%2C%22showPost%22:null%2C%22showAnonymityName%22:%22%E5%8C%BF%E5%90%8D%E7%94%A8%E6%88%B7e24ca20%22%2C%22messageBubbleCount%22:%220%22%2C%22claimPoint%22:%220%22%2C%22token%22:%22eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzk0MDI5MDIzNiIsImlhdCI6MTYxODczNDcwMSwiZXhwIjoxNjUwMjcwNzAxfQ.hkhCGDbmKfgIrWo47ka6-aoU6FDBPOc1OYQVb8CUF9rXgayDc1-CC6M1p4DxWWvZqe3ReDUzCu-2idHNbZ-uZQ%22%2C%22schoolAuthStatus%22:%222%22%2C%22userId%22:%22237292064%22%2C%22scoreUnit%22:%22%22%2C%22redPoint%22:%220%22%2C%22myTidings%22:%220%22%2C%22companyAuthStatus%22:%222%22%2C%22originalScore%22:%220%22%2C%22myAnswerCount%22:%220%22%2C%22myQuestionCount%22:%220%22%2C%22signUp%22:%221%22%2C%22realBossStatus%22:%222%22%2C%22privateMessagePointWeb%22:%220%22%2C%22nickname%22:%22%E5%87%AF%E6%92%92%22%2C%22headPicUrl%22:%22https://cdn.tianyancha.com/design/avatar/v3/man12.png%22%2C%22privateMessagePoint%22:%220%22%2C%22bossStatus%22:%222%22%2C%22isClaim%22:%220%22%2C%22yellowDiamondEndTime%22:%220%22%2C%22new%22:%221%22%2C%22yellowDiamondStatus%22:%22-1%22%2C%22pleaseAnswerCount%22:%220%22%2C%22bizCardUnread%22:%220%22%2C%22vnum%22:%220%22%2C%22mobile%22:%2213940290236%22%2C%22riskManagement%22:{%22servicePhone%22:null%2C%22mobile%22:13940290236%2C%22title%22:null%2C%22currentStatus%22:null%2C%22lastStatus%22:null%2C%22quickReturn%22:false%2C%22oldVersionMessage%22:null%2C%22riskMessage%22:null}}; auth_token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzk0MDI5MDIzNiIsImlhdCI6MTYxODczNDcwMSwiZXhwIjoxNjUwMjcwNzAxfQ.hkhCGDbmKfgIrWo47ka6-aoU6FDBPOc1OYQVb8CUF9rXgayDc1-CC6M1p4DxWWvZqe3ReDUzCu-2idHNbZ-uZQ; tyc-user-info-save-time=1618734701057; tyc-user-phone=%255B%252213940290236%2522%255D; CT_TYCID=0ddee1ad02dc48a691c0902555d25ffa; RTYCID=83614d51398445e09a9bfb91cb3c75cf; cloud_token=fb04bf000c1c4ff889b3b6358a417dff; cloud_utm=c849722512cc4c41989edb7d03b748da; searchSessionId=1618734883.11371051; relatedHumanSearchGraphId=3394970869; relatedHumanSearchGraphId.sig=DT0YiJ0CryZe7xMOSfdSKSlcLRNB23bQ17HzAbBQB8g; Hm_lpvt_e92c8d65d92d534b0fc290df538b4758=1618734889',
         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36 Edg/89.0.774.77'}

html=requests.get(url,headers=headers)
soup =BeautifulSoup(html.text,'lxml')
innerurl=soup.select_one('a.name')['href']
print(innerurl)

你可能感兴趣的:(python 爬虫--天眼查获取内链)