我有一段时间以来试图想方设法用C++做一些简单的网站抓取.我偶然发现了cURL库,但我无法正确安装,所以我会尝试另一种方法.
你们有谁知道任何方法吗?如果后面详细解释如何使用C++在Win32上安装它,那么使用cURL是一个可以接受的答案.
我可以在某种程度上更容易地做到这一点,还是在C++中是不可能的任务?如果是这样,冒险使用C#会更容易吗,虽然我之前从未使用过它?
我在上个月左右一直在学习python的基础知识,虽然我非常擅长打印'hello world',但我想学习一些额外的功能.我已下载BeautifulSoup4并使用Python2.7.我的目标是能够从CNN或其他新闻来源获取文章并能够废弃4件事:1)链接到网站2)发布日期文章3)文章标题4)文章文本
我已经在stackoverflow中搜索了其他问题并查看了其他示例代码,但是我将它应用于我想要做的事情时遇到了问题.我看到的大多数例子都是在刮擦时间或天气.我的主要问题是,当我查看特定网站的源代码时,我很难知道我应该使用哪些标签.
例如,如果我想废弃以上4件事:http: //www.cnn.com/2013/10/29/us/florida-shooting-cell-phone-blocks-bullet/index.html?http = ju_c2
代码会是什么样的?
这是我的Python代码:
import urllib2
from bs4 import BeautifulSoup
page = urllib2.urlopen("http://www.amazon.com/")
soup = BeautifulSoup(page)
print soup
Run Code Online (Sandbox Code Playgroud)
它适用于 google.com 和许多其他网站,但不适用于 amazon.com。
我可以在浏览器中打开 amazon.com,但生成的“汤”仍然没有。
此外,我发现它也无法从 appannie.com 上抓取。然而,代码并没有给出任何结果,而是返回一个错误:
HTTPError: HTTP Error 503: Service Temporarily Unavailable
Run Code Online (Sandbox Code Playgroud)
所以我怀疑亚马逊和 App Annie 是否会阻止抓取。
我是使用PHP而不是PHP本身的Web抓取新手.我的问题不是正则表达式相关,但似乎直接与booking.com网站有关.我想在特定城市刮取酒店的价格.为此,我在预订页面中复制了浏览器中的URL,并将其粘贴到我的代码中.
这是页面.
这是我的代码:
<?php
function getHTML($url,$timeout)
{
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
return @curl_exec($ch);
}
$html=getHTML("http://www.booking.com/searchresults.en.html?dcid=1;checkin_monthday=25;checkin_year_month=2014-7;checkout_monthday=26;checkout_year_month=2014-7;city=-1461464;class_interval=1;csflt=%7B%7D;interval_of_time=undef;no_rooms=1;or_radius=0;property_room_info=1;review_score_group=empty;score_min=0;src=city;ssb=empty;;nflt=ht_id%3D204%3Bclass%3D3%3B;unchecked_filter=class",10);
echo $html;
?>
Run Code Online (Sandbox Code Playgroud)
我确实打印了一个预订页面,但它没有考虑到URL中的参数,因为在页面上我得到它要求预订日期和城市...
我尝试在几个浏览器中粘贴此URL并隐藏窗口(以查看URL是否链接到Cookie或其他内容),并且它运行正常.也许我在cURL请求中错过了一个参数......
因此,我正在编写一个带有R的网络刮刀来搜索zillow,了解西澳州每个县的房屋中值.我正在使用rvest包,这里是有问题的代码:
URL <- "https://en.wikipedia.org/wiki/List_of_counties_in_Washington"
wiki <- html(URL)
#Getting the list of counties in WA
counties <- wiki %>%
html_nodes(".wikitable td:nth-child(1) a") %>%
html_text()
#Putting together a list to pull my search terms from
searchTerms <- list()
for(i in 1:length(counties)) {
searchTerms[[i]] <- paste0(counties[i], ", WA", sep="")
}
searchTerms <- gsub(",", "", searchTerms)
searchTerms <- gsub(" ", "-", searchTerms)
homeValues <- list()
#Getting the HTML for each county using the search terms in the URL,
#eventually it will pull the homeValues …Run Code Online (Sandbox Code Playgroud) 我有一个基于Express的Node应用程序,它使用Web scraper加载和解析数据.
我已经阅读了很多关于NodeJS的可扩展性以及能够处理一堆并发连接的内容,但是当你运行一个web scraper(发送1000多个并发请求)时,我觉得事情开始崩溃了一点.
运行时,我的服务器对其他API请求没有响应,并且一次运行多个实例会导致速度降低到蜗牛的速度.
我找不到任何关于限制是什么,它们应该是什么,我应该聚集在一起的请求数等等的文档.
我应该将刮刀的要求限制为每秒10次吗?每秒100?每秒1000?或者我可能会增加在我的VPS上分配给我的节点进程的CPU /内存量?
编辑:对于那些投票结束的人,因为这个问题太基于意见,这具体是我要问的:
我希望从 sec.gov 网站上抓取大量文件,到目前为止进展顺利。问题是旧文件采用 .txt 格式,并且没有任何真正的 HTML 格式。有什么方法可以使用Python从这些文件中获取信息吗?
我有大约 30,000 个这样的人要做,而旧文档是我老板真正想要的......我目前正在使用 BeautifulSoup4 来处理其他格式正确的片段。
提前致谢!
我有这个简单的代码:
import requests
r = requests.get('https://yahoo.com')
print(r.url)
Run Code Online (Sandbox Code Playgroud)
执行后打印:
https://uk.yahoo.com/?p=us
Run Code Online (Sandbox Code Playgroud)
我想看看:
在到达之前发生了多少次重定向https://uk.yahoo.com/?p=us(显然,我最初输入时有重定向https://yahoo.com)?
我还想保存每一页的内容,而不仅仅是最后一页。这个怎么做?
python web-scraping python-3.x python-requests python-requests-html
在我的项目中,我从亚马逊抓取数据。我将其部署在 Pythonanywhere 上(我使用付费帐户)。但是有一个问题,当我在 Pythonanywhere 上尝试时,代码(我使用的是 BeautifulSoup4)无法获取网站的 html。它获得了亚马逊的“出问题了”网站。但在我本地它工作得很好。我认为它与用户代理有关。在我的本地,我使用我自己的用户代理。部署时我应该使用哪个用户代理?我该如何解决这个问题?
这是我的代码:
URL = link ##some amazon link
headers = {"User-Agent": " ##my user agent"}
page = requests.get(URL, headers=headers)
soup1 = BeautifulSoup(page.content, 'html.parser')
soup2 = BeautifulSoup(soup1.prettify(), "html.parser")
Run Code Online (Sandbox Code Playgroud)
有什么办法可以在 Pythonanywhere 上做到这一点吗?
我正在尝试构建一个机器人来从 Twitter 上抓取一些帖子以用于学习目的。问题是浏览器打开并要求登录。但实际上我之前已经登录过。为什么要求重新登录?我的代码中是否缺少某些内容?如果我在这里出错,有人可以指导我吗?如果我不登录,它将给出空的数据框。请帮我。
import pandas as pd
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
driver=webdriver.Chrome()
driver.get('https://twitter.com/search?q=python&src=typed_query')
driver.maximize_window()
time.sleep(5)
tweets=driver.find_elements(by='xpath',value='//article[@role="article"]')
user_data=[]
text_data=[]
for tweet in tweets:
user=tweet.find_elements(by='xpath',value='//span[contains(text(),'@')]').text
text=tweet.find_elements(by='xpath',value='//div[@lang]').text
user.append(user_data)
text.append(text_data)
driver.quit()
df_tweets=pd.DataFrame({'user':user_data,'text':text_data})
df_tweets.to_csv('tweets.csv',index=False)
print(df_tweets)
Run Code Online (Sandbox Code Playgroud) python web-scraping selenium-chromedriver selenium-webdriver
web-scraping ×10
python ×6
python-3.x ×2
c++ ×1
curl ×1
express ×1
javascript ×1
node.js ×1
php ×1
r ×1
rvest ×1
user-agent ×1
vps ×1