百度搜索 抓取真实url

现在的百度搜索url都是加密的,不是真实url。比如搜索豆瓣

 复制链接地址得到的url如下:https://www.baidu.com/link?url=vsdsl04PUGwYT-udMGNDBSgQ4D62grmcfm8fM4LVjYLVVMoaXT6EoDxqw0FKxHcy&wd=&eqid=979239ad000511ed0000000463453c3e

访问这个加密链接并抓包,得到的响应如下:

<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta content="always" name="referrer">
	<script>
		try{if(window.opener&&window.opener.bds&&window.opener.bds.pdc&&window.opener.bds.pdc.sendLinkLog){window.opener.bds.pdc.sendLinkLog();}}catch(e) {};var timeout = 0;if(/bdlksmp/.test(window.location.href)){var reg = /bdlksmp=([^=&]+)/,matches = window.location.href.match(reg);timeout = matches[1] ? matches[1] : 0};setTimeout(function(){window.location.replace("https://www.douban.com/")},timeout);window.opener=null;
	</script>
	<noscript>
		<META http-equiv="refresh" content="0;URL='https://www.douban.com/'"></noscript>

我用的语言是 python,findall得到真实ip

innerurl = re.findall("0;URL=\'(.*?)\'", text)[0]

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要抓取百度搜索界面的所有URL,可以使用Python的爬虫库和相关技术来实现。 首先需要安装所需的Python爬虫库,如Requests和BeautifulSoup。可以使用pip命令进行安装。 ```python pip install requests pip install beautifulsoup4 ``` 然后,需要编写Python代码来发送请求并解析页面内容。可以使用Requests库发送HTTP请求,并使用BeautifulSoup库解析HTML。 ```python import requests from bs4 import BeautifulSoup # 发送HTTP请求获取搜索结果页面 def get_search_page(query): url = "https://www.baidu.com/s" params = { "wd": query } response = requests.get(url, params=params) return response.text # 解析搜索结果页面中的URL def parse_urls(page): soup = BeautifulSoup(page, "html.parser") urls = [] for link in soup.find_all("a"): href = link.get("href") if href.startswith("http"): urls.append(href) return urls # 调用函数获取搜索结果页面并解析URL search_query = "Python" search_page = get_search_page(search_query) urls = parse_urls(search_page) # 打印所有抓取到的URL for url in urls: print(url) ``` 以上代码中,`get_search_page`函数发送HTTP请求并返回搜索结果页面的内容。`parse_urls`函数使用BeautifulSoup解析HTML页面,并找到所有链接标签,然后提取其中的URL。最后,调用这两个函数,并打印所有抓取到的URL。 需要注意的是,对于抓取百度搜索界面的所有URL,可能需要应对反爬虫机制,例如添加请求头部信息、处理验证码等。此外,使用爬虫时应遵守网站的爬虫规则和法律法规。 ### 回答2: 要抓取百度搜索界面的所有 URL,可以使用爬虫技术结合 Python 中的相关库来实现。下面是一个简单的示例代码: 1. 导入所需的库: ```python import requests from bs4 import BeautifulSoup ``` 2. 定义一个函数,用于获取百度搜索结果页面的 HTML 内容: ```python def get_search_results(keyword): url = 'https://www.baidu.com/s' params = {'wd': keyword} headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'} response = requests.get(url, params=params, headers=headers) if response.status_code == 200: return response.text else: return None ``` 3. 定义一个函数,用于从 HTML 内容中提取所有搜索结果的 URL: ```python def extract_urls(html): urls = [] soup = BeautifulSoup(html, 'html.parser') results = soup.find_all('div', class_='result') for result in results: link = result.find('a') url = link['href'] urls.append(url) return urls ``` 4. 调用上述函数获取搜索结果页面的 HTML 内容,并提取其中的 URL: ```python keyword = 'Python 编程' html = get_search_results(keyword) if html: urls = extract_urls(html) for url in urls: print(url) else: print('获取搜索结果页面失败') ``` 以上代码使用了 requests 库发送 HTTP 请求,模拟浏览器访问百度搜索页面,并使用 BeautifulSoup 库解析 HTML 内容以提取所需的 URL。通过调用这些函数,即可实现抓取百度搜索界面的所有 URL。需要注意的是,代码中的 User-Agent 需要根据实际情况进行调整,以避免被百度屏蔽。 ### 回答3: 要抓取百度搜索界面的所有URL,可以使用Python的第三方库BeautifulSoup和requests来实现。首先,我们需要安装这两个库: ``` pip install beautifulsoup4 pip install requests ``` 然后,创建一个Python文件,导入所需的库: ``` import requests from bs4 import BeautifulSoup ``` 接下来,我们可以定义一个函数来抓取百度搜索界面的所有URL: ``` def get_baidu_urls(search_query): url = 'https://www.baidu.com/s' params = { 'wd': search_query } response = requests.get(url, params=params) soup = BeautifulSoup(response.text, 'html.parser') urls = [] for link in soup.find_all('a'): url = link.get('href') # 筛选出百度搜索结果的URL if url.startswith('/link') or url.startswith('http'): urls.append(url) return urls ``` 在上述代码中,我们首先指定了要搜索的关键词,然后构建了一个URL,该URL用于发送GET请求来获取百度搜索结果页面。然后,我们使用BeautifulSoup解析页面的HTML内容,并筛选出所有的URL。最后,我们返回这些URL列表。 我们可以调用这个函数来抓取百度搜索界面的所有URL,例如: ``` urls = get_baidu_urls('Python教程') print(urls) ``` 这样就能获取到百度搜索界面中包含关键词“Python教程”的所有URL了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值