假设我想从搜索“hi google”中抓取结果(只是一个例子)。我正在使用带有 Node.js 的 Puppeteer 进行抓取。我使用以下代码:
const puppeteer = require('puppeteer');
scrape = async function () {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto("https://www.google.com/search?q=hi+google&rlz=1C1CHBF_enUS879US879&oq=hi+google&aqs=chrome..69i57j0l3j46j69i60l3.1667j0j7&sourceid=chrome&ie=UTF-8", { waitUntil: "networkidle2" });
await page.setViewport({ width: 1366, height: 663 });
await page.waitForSelector('.xpd');
let data = await page.evaluate(() => {
return document.querySelectorAll('.xpd')[16];
});
await browser.close();
return data;
}
scrape()
.then(function(result) {
console.log(result);
})
Run Code Online (Sandbox Code Playgroud)
当浏览器启动时,它会立即转到 reCAPTCHA 页面:
有没有办法超越这个问题?我在网上做了一些研究,但这些结果要么是 1. 非常理论化,我不知道如何在我的代码中实现这些,要么 2. Python 解决方案,我不确定其中一些解决方案会如何傀儡师。我遇到的最有用的结果是随机定时抓取以使请求看起来像人类,但正如您所看到的,即使只检索一个数据元素也不起作用,它只会立即将您带到 reCAPTCHA 页面。
谢谢。
我想存储:
在我的名为products_data的表中,其filds名称为PID,product_name,category,subcategory,product_price和product_company.
我curl_init()在php中使用函数首先废弃网站URL,接下来我想将产品数据存储在我的数据库表中.以下是我迄今为止所做的事情:
$sites[0] = 'http://www.babyoye.com/';
foreach ($sites as $site)
{
$ch = curl_init($site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
$title_start = '<div class="info">';
$parts = explode($title_start,$html);
foreach($parts as $part){
$link = explode('<a href="/d/', $part);
$link = explode('">', $link[1]);
$url = 'http://www.babyoye.com/d/'.$link[0];
// now for the title we need to follow a similar process:
$title = explode('<h2>', $part);
$title = explode('</h2>', $title[1]);
$title = strip_tags($title[0]);
// INSERT DB CODE HERE e.g.
$db_conn = …Run Code Online (Sandbox Code Playgroud) 我试图从Zillow收集数据是不成功的.
例:
url = https://www.zillow.com/homes/for_sale/Los-Angeles-CA_rb/?fromHomePage=true&shouldFireSellPageImplicitClaimGA=false&fromHomePageTab=buy
我想从洛杉矶的所有家庭中提取地址,价格,zestimates,地点等信息.
我已经尝试使用像BeautifulSoup这样的包进行HTML抓取.我也尝试过使用json.我几乎肯定Zillow的API没有帮助.我的理解是,API最适合收集特定属性的信息.
我已经能够从其他站点获取信息,但似乎Zillow使用动态ID(更改每次刷新)使得访问该信息变得更加困难.
更新: 尝试使用以下代码,但仍然没有产生任何结果
import requests
from bs4 import BeautifulSoup
url = 'https://www.zillow.com/homes/for_sale/Los-Angeles-CA_rb/?fromHomePage=true&shouldFireSellPageImplicitClaimGA=false&fromHomePageTab=buy'
page = requests.get(url)
data = page.content
soup = BeautifulSoup(data, 'html.parser')
for li in soup.find_all('div', {'class': 'zsg-photo-card-caption'}):
try:
#There is sponsored links in the list. You might need to take care
#of that
#Better check for null values which we are not doing in here
print(li.find('span', {'class': 'zsg-photo-card-price'}).text)
print(li.find('span', {'class': 'zsg-photo-card-info'}).text)
print(li.find('span', {'class': 'zsg-photo-card-address'}).text)
print(li.find('span', {'class': 'zsg-photo-card-broker-name'}).text)
except :
print('An error occured')
Run Code Online (Sandbox Code Playgroud) 无法找到使用 splinter 进行滚动的命令。无论我在哪里搜索,都只能找到硒而不是碎片。
我正在尝试从不同机场之间的路线上的站点提取数据.用户打算选择两个机场,然后程序将在给定的一天向他们显示所有不同的路线.只有在网站上搜索路由后,无论您正在查看哪条路线,网址都会更改为相同的.asp域名.有没有办法在不知道URL的情况下从特定路由中抓取数据,或者是否有可能获得真正的URL?
在很多网站上,您都可以从Instagram个人资料中获取所有关注者的列表。例如Jennifer Lopez的个人资料。如果我单击关注者并向下滚动漏洞列表,则只会看到大约1000个用户。有什么方法可以获取所有关注者的列表,或者是介于1万到10万用户之间的列表?其他人如何做?
以下几页似乎有效:
如果您能帮助我,我将不胜感激!
xpath从视频中获取 YouTube 喜欢和不喜欢的正确方法是什么?
youtube xpath google-sheets web-scraping google-sheets-formula
我创建了一个脚本来使用请求模块从该网站收集不同的公司名称,但是当我执行该脚本时,它最终什么也没得到。我在页面源中查找了公司名称,发现这些名称在那里可用,因此它们似乎是静态的。
import requests
from bs4 import BeautifulSoup
link = 'https://clutch.co/agencies/digital-marketing'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
}
with requests.Session() as s:
s.headers.update(headers)
res = s.get(link)
soup = BeautifulSoup(res.text,"lxml")
for item in soup.select("h3.company_info > a"):
print(item.text)
Run Code Online (Sandbox Code Playgroud) python beautifulsoup web-scraping python-3.x python-requests
Oxford, Oxfordshire我正在尝试使用请求模块从此网页中抓取此搜索的不同列表。这是我点击搜索按钮之前输入框的样子。
我已经定义了一个准确的选择器来定位列表,但脚本无法获取任何数据。
import requests
from pprint import pprint
from bs4 import BeautifulSoup
link = 'https://www.zoopla.co.uk/search/'
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9,bn;q=0.8',
'Referer': 'https://www.zoopla.co.uk/for-sale/',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
}
params = {
'view_type': 'list',
'section': 'for-sale',
'q': 'Oxford, Oxfordshire',
'geo_autocomplete_identifier': 'oxford',
'search_source': 'home'
}
res = requests.get(link,params=params,headers=headers)
soup = BeautifulSoup(res.text,"html5lib")
for item in soup.select("[id^='listing'] a[href^='/for-sale/details/']:has(h2[data-testid='listing-title'])"):
print(item.get("href"))
Run Code Online (Sandbox Code Playgroud)
编辑:
如果我尝试类似以下的操作,脚本似乎可以完美运行。唯一的主要问题是我必须在标头中使用硬编码的 cookie,这些 cookie …